private void HandleDoubleClick(object sender, MouseButtonEventArgs e) { ListBoxItem lbi = sender as ListBoxItem; AccessListEntry address = null; if (lbi.DataContext is PlayerInfo) { PlayerInfo pi = lbi.DataContext as PlayerInfo; address = ParseText(pi.Address.ToString()); } else if (lbi.DataContext is AccessListEntry) { address = lbi.DataContext as AccessListEntry; } //AccessListEntry address = ParseText(((ListBoxItem)sender).DataContext.ToString()); if (address != null) { if (AccessControl.Instance.AccessList.Contains(address)) { AccessControl.Instance.AccessList.Remove(address); } else { AccessControl.Instance.AccessList.Add(address); } } }
private async Task AddItemToRecentListAsync(IStorageItem item, AccessListEntry entry) { BitmapImage ItemImage; string ItemPath; string ItemName; StorageItemTypes ItemType; bool ItemFolderImgVis; bool ItemEmptyImgVis; bool ItemFileIconVis; if (item.IsOfType(StorageItemTypes.File)) { // Try to read the file to check if still exists // This is only needed to remove files opened from a disconnected android/MTP phone if (string.IsNullOrEmpty(item.Path)) // This indicates that the file was open from an MTP device { using (var inputStream = await item.AsBaseStorageFile().OpenReadAsync()) using (var classicStream = inputStream.AsStreamForRead()) using (var streamReader = new StreamReader(classicStream)) { // NB: this might trigger the download of the file from OneDrive streamReader.Peek(); } } ItemName = item.Name; ItemPath = string.IsNullOrEmpty(item.Path) ? entry.Metadata : item.Path; ItemType = StorageItemTypes.File; ItemImage = new BitmapImage(); BaseStorageFile file = item.AsBaseStorageFile(); using var thumbnail = await file.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.ListView, 24, Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale); if (thumbnail == null) { ItemEmptyImgVis = true; } else { await ItemImage.SetSourceAsync(thumbnail); ItemEmptyImgVis = false; } ItemFolderImgVis = false; ItemFileIconVis = true; recentItemsCollection.Add(new RecentItem() { RecentPath = ItemPath, Name = ItemName, Type = ItemType, FolderImg = ItemFolderImgVis, EmptyImgVis = ItemEmptyImgVis, FileImg = ItemImage, FileIconVis = ItemFileIconVis }); } }
/// <summary> /// Initializes the model from the provided struct. /// </summary> /// <param name="accessListEntry">The AccessListEntry to use as a reference.</param> public StoredFileDescriptor(AccessListEntry accessListEntry) { this.accessListEntry = accessListEntry; this.isAppOwned = false; this.forgetCommand = new AsyncActionCommand(FireForgetRequested); this.exportCommand = new ActionCommand(FireExportRequested); this.updateCommand = new AsyncActionCommand(() => IsAppOwned, FireUpdateRequested); this.openCommand = new ActionCommand(FireOpenRequested); }
protected override void execute(User source, string destination, string[] tokens) { if (tokens.Length < 1) { EyeInTheSkyBot.IrcFreenode.ircNotice(source.nickname, "More params pls!"); return; } string mode = GlobalFunctions.popFromFront(ref tokens); if (mode == "add") { if (tokens.Length < 2) { EyeInTheSkyBot.IrcFreenode.ircNotice(source.nickname, "More params pls!"); return; } string hostmask = GlobalFunctions.popFromFront(ref tokens); string accesslevel = GlobalFunctions.popFromFront(ref tokens); var level = (User.UserRights)Enum.Parse(typeof(User.UserRights), accesslevel); if(source.accessLevel != User.UserRights.Developer && level >= source.accessLevel) { EyeInTheSkyBot.IrcFreenode.ircNotice(source.nickname, "Access denied."); return; } var ale = new AccessListEntry(hostmask, level); EyeInTheSkyBot.Config.accessList.Add(hostmask, ale); EyeInTheSkyBot.IrcFreenode.ircPrivmsg(destination, "Done."); } if (mode == "del") { if (tokens.Length < 1) { EyeInTheSkyBot.IrcFreenode.ircNotice(source.nickname, "More params pls!"); return; } string hostmask = GlobalFunctions.popFromFront(ref tokens); EyeInTheSkyBot.Config.accessList.Remove(hostmask); EyeInTheSkyBot.IrcFreenode.ircPrivmsg(destination, "Done."); } if (mode == "list") { EyeInTheSkyBot.IrcFreenode.ircNotice(source.nickname, "Access list:"); foreach (KeyValuePair<string, AccessListEntry> accessListEntry in EyeInTheSkyBot.Config.accessList) { EyeInTheSkyBot.IrcFreenode.ircNotice(source.nickname, accessListEntry.Value.HostnameMask + " = " + accessListEntry.Value.AccessLevel); } EyeInTheSkyBot.IrcFreenode.ircNotice(source.nickname, "End of access list."); } EyeInTheSkyBot.Config.save(); }
public static bool GenerateEntryFromString(string s, out AccessListEntry target) { if (!AccessIP.TryParse(s, out target)) { if (!AccessIPRange.TryParse(s, out target)) { return(false); } } return(true); }
private static AccessListEntry ParseText(string text) { AccessListEntry e = null; if (!AccessIP.TryParse(text, out e)) { if (!AccessIPRange.TryParse(text, out e)) { return(null); } } return(e); }
private void DeleteItem_Click(object sender, RoutedEventArgs e) { // https://stackoverflow.com/questions/34445579/how-to-get-listview-item-content-on-righttapped-event-of-an-universal-windows-ap AccessListEntry entry = (AccessListEntry)((FrameworkElement)e.OriginalSource).DataContext; string token = entry.Token; // Remove from MRU // https://docs.microsoft.com/en-us/windows/uwp/files/how-to-track-recently-used-files-and-folders var mru = StorageApplicationPermissions.MostRecentlyUsedList; mru.Remove(token); MruList.ItemsSource = null; mruView = StorageApplicationPermissions.MostRecentlyUsedList.Entries; MruList.ItemsSource = mruView; }
public async Task OpenSolutionAsync(IStorageFolder folder) { AccessListEntry accessListEntry = RecentSolutions.FirstOrDefault(e => e.Metadata == folder.Path); if (string.IsNullOrEmpty(accessListEntry.Token)) { string token = StorageApplicationPermissions.MostRecentlyUsedList.Add(folder, folder.Path); accessListEntry = new AccessListEntry { Token = token, Metadata = folder.Path }; RecentSolutions.Add(accessListEntry); } if (JumpList.IsSupported()) { JumpList jumpList = await JumpList.LoadCurrentAsync(); jumpList.SystemGroupKind = JumpListSystemGroupKind.Recent; JumpListItem?existingJumpListItem = jumpList.Items.FirstOrDefault(j => j.Arguments == accessListEntry.Token); if (existingJumpListItem is null || existingJumpListItem.RemovedByUser) { JumpListItem jumpListItem = JumpListItem.CreateWithArguments(accessListEntry.Token, folder.Name); jumpListItem.Description = folder.Path; jumpListItem.GroupName = "Recent"; jumpList.Items.Add(jumpListItem); } await jumpList.SaveAsync(); } if (RootFolder != null) { await CoreApplication.RequestRestartAsync(accessListEntry.Token); } else { RootFolder = (StorageFolder)folder; await RegisterBackgroundTaskAsync(); RootFolderLoaded?.Invoke(this, new RootFolderLoadedEventArgs(RootFolder)); await LoadSolutionAsync(); } }
private async void MruList_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) { if ((sender as ListView).SelectedItem == null) { return; } AccessListEntry entry = (AccessListEntry)(sender as ListView).SelectedItem; string token = entry.Token; try { StorageFile file = await StorageApplicationPermissions.MostRecentlyUsedList.GetItemAsync(token) as StorageFile; if (file != null) { Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(MailPage), file); // Add to MRU // https://docs.microsoft.com/en-us/windows/uwp/files/how-to-track-recently-used-files-and-folders var mru = StorageApplicationPermissions.MostRecentlyUsedList; string mruToken = mru.Add(file, file.Name); MruList.ItemsSource = null; mruView = StorageApplicationPermissions.MostRecentlyUsedList.Entries; MruList.ItemsSource = mruView; } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); ContentDialog dlg = new ContentDialog() { Title = $"\"{entry.Metadata}\" is not available", Content = "Selected file may be moved/renamed/deleted.", CloseButtonText = "OK" }; _ = dlg.ShowAsync(); // Remove from MRU // https://docs.microsoft.com/en-us/windows/uwp/files/how-to-track-recently-used-files-and-folders var mru = StorageApplicationPermissions.MostRecentlyUsedList; mru.Remove(token); MruList.ItemsSource = null; mruView = StorageApplicationPermissions.MostRecentlyUsedList.Entries; MruList.ItemsSource = mruView; } }
private async void OpenWindowButton_Click(object sender, RoutedEventArgs e) { // https://stackoverflow.com/questions/34445579/how-to-get-listview-item-content-on-righttapped-event-of-an-universal-windows-ap AccessListEntry entry = (AccessListEntry)((FrameworkElement)e.OriginalSource).DataContext; string token = entry.Token; try { StorageFile file = await StorageApplicationPermissions.MostRecentlyUsedList.GetItemAsync(token) as StorageFile; if (file != null) { // Open file on this app var options = new LauncherOptions(); options.TargetApplicationPackageFamilyName = Package.Current.Id.FamilyName; await Launcher.LaunchFileAsync(file, options); // Add to MRU // https://docs.microsoft.com/en-us/windows/uwp/files/how-to-track-recently-used-files-and-folders var mru = StorageApplicationPermissions.MostRecentlyUsedList; string mruToken = mru.Add(file, file.Name); MruList.ItemsSource = null; mruView = StorageApplicationPermissions.MostRecentlyUsedList.Entries; MruList.ItemsSource = mruView; } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); ContentDialog dlg = new ContentDialog() { Title = $"\"{entry.Metadata}\" is not available", Content = "Selected file may be moved/renamed/deleted.", CloseButtonText = "OK" }; _ = dlg.ShowAsync(); // Remove from MRU // https://docs.microsoft.com/en-us/windows/uwp/files/how-to-track-recently-used-files-and-folders var mru = StorageApplicationPermissions.MostRecentlyUsedList; mru.Remove(token); MruList.ItemsSource = null; mruView = StorageApplicationPermissions.MostRecentlyUsedList.Entries; MruList.ItemsSource = mruView; } }
/// <summary> /// Asynchronously clears and adds back <see cref="StoredFileDescriptor"/> to updated /// <see cref="StoredFiles"/>. /// </summary> /// <returns></returns> private async Task ResyncFiles() { ClearAllFiles(); foreach (ITestableFile file in await this.proxyProvider.GetKnownProxiesAsync() .ConfigureAwait(false) ) { var allStoredFiles = this.accessList.Entries .Select(e => new { Entry = e, FileTask = this.accessList.GetFileAsync(e.Token) }); AccessListEntry?entry = null; foreach (var stored in allStoredFiles) { ITestableFile storedFile = await stored.FileTask.ConfigureAwait(false); if (storedFile.AsIStorageItem.Path == file.AsIStorageItem.Path) { entry = stored.Entry; } } // If we couldn't find the file in the access list, add it. // This asserts because these lists shouldn't be out of sync in the first place. if (!entry.HasValue) { string metadata = file.AsIStorageItem.Name; entry = new AccessListEntry { Metadata = metadata, Token = this.accessList.Add(file, metadata) }; DebugHelper.Assert(false); } StoredFileDescriptor descriptor = new StoredFileDescriptor( entry.Value ); descriptor.IsAppOwned = await this.proxyProvider.PathIsInScopeAsync(file.AsIStorageItem2); // Wire events WireDescriptorEvents(descriptor); AddFile(descriptor); } }
/// <summary> /// Reads the <see cref="DatabaseRegistration"/> from file access entry. /// </summary> /// <param name="entry">File access entry.</param> /// <returns>The database registration, or <c>null</c> if not valid.</returns> private static DatabaseRegistration Read(AccessListEntry entry) { try { var meta = JsonConvert.DeserializeObject <DatabaseMetaData>(entry.Metadata); return(new DatabaseRegistration { Id = entry.Token, Name = meta.Name, }); } catch { return(null); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); // Remove ads if purchased if (App.licenseInformation.ProductLicenses["removedAds"].IsActive) { RemoveAds(); } // Show most recent files mruFiles = new ObservableCollection <RecentFile>(); AccessListEntryView mruEntries = null; if ((bool)App.AppSettings[App.SHOW_RECENT_FILES]) { mruEntries = StorageApplicationPermissions.MostRecentlyUsedList.Entries; } // If no recent file if (mruEntries == null || mruEntries.Count == 0) { this.recentFileTitle.Text = "No Recent File."; this.OpenNew.Content = "Open a File..."; AppEventSource.Log.Debug("MainPage: No recent file found."); } else { // Show a list of recent used file for (int i = 0; i < mruEntries.Count; i++) { AccessListEntry entry = mruEntries[i]; RecentFile file = new RecentFile(entry.Token); string[] split = entry.Metadata.Split(new string[] { MRU_DELIMITER }, 2, StringSplitOptions.RemoveEmptyEntries); file.Filename = split[0]; file.LastAccessTime = Convert.ToDateTime(split[1]); file.Identifier = PREFIX_RECENT_FILE + i.ToString(); mruFiles.Add(file); if (i == 10) { break; } } this.RecentFileList.DataContext = mruFiles; AppEventSource.Log.Debug("MainPage: Recent files added."); } }
private async void btnGetMostRecentlyUsedList_Click(object sender, RoutedEventArgs e) { AccessListEntryView entries = StorageApplicationPermissions.MostRecentlyUsedList.Entries; if (entries.Count > 0) { // 通过 token 值,从“最近访问列表”中获取文件对象 AccessListEntry entry = entries[0]; StorageFile storageFile = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(entry.Token); string textContent = await FileIO.ReadTextAsync(storageFile); lblMsg.Text = "MostRecentlyUsedList 的第一个文件的文本内容:" + textContent; } else { lblMsg.Text = "最近访问列表中无数据"; } }
/// <summary> /// This method will remove a folder from future access list (Morteza). /// </summary> /// <param name="folder">A folder for deletion from future access list (Morteza).</param> public static void DeleteFolderFromFutureAccessList(string folderPath) { AccessListEntry deletedVideoFolderInFutureAccessList = GetFutureAccessListFolderByFolderPath(folderPath); StorageApplicationPermissions.FutureAccessList.Remove(deletedVideoFolderInFutureAccessList.Token); }
private async Task AddAUserFolder(AccessListEntry item, StorageFolder retrievedFolder) { var folderItem = AddNewItem(ExplorerGroups[1], retrievedFolder, item.Token); await GetSubImage(folderItem); }