public string UnpinElement(IPFSElement el, bool deleteFile = true) { try { if (deleteFile) { if (el.IsLinkOnly) { File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\.ipfs\" + el.Name + ".lnk"); File.Delete(eponaSharedFolderPath + "\\" + el.Name + ".lnk"); } else { if (el.FileType.Equals(FileType.FOLDER)) { File.Delete(eponaSharedFolderPath + "\\" + el.Name + ".lnk"); } else { File.Delete(eponaSharedFolderPath + "\\" + el.Name); } } } return(ExecuteCommand("pin rm " + el.Hash)); } catch (Exception) { return(null); } }
public void ToggleActiveState(int index) { if (index < elements.Count) { IPFSElement el = (IPFSElement)elements[index]; el.Active = !el.Active; if (File.Exists(jsonFilePath)) { string json = JsonConvert.SerializeObject(elements); File.SetAttributes(jsonFilePath, FileAttributes.Normal); File.WriteAllText(jsonFilePath, json); File.SetAttributes(jsonFilePath, FileAttributes.Hidden); } this.objectListView1.RefreshObjects(elements); if (el.Active) { AddElement(el.Path); } else { UnpinElement(el); } } }
private void checkSharedFolder() { try { string[] entries = Directory.GetFileSystemEntries(eponaSharedFolderPath, "*", SearchOption.AllDirectories); bool[] fileStatus = new bool[elements.Count]; foreach (string entry in entries) { for (int i = 0; i < elements.Count; i++) { IPFSElement el = (IPFSElement)elements[i]; if (entry.Equals(el.Path) || (Path.GetFileName(entry)).Equals(Path.GetFileName(el.Path.Replace(' ', '_') + ".lnk"))) { fileStatus[i] = true; } } } for (int i = 0; i < fileStatus.Length; i++) { if (i < elements.Count) { IPFSElement el = (IPFSElement)elements[i]; if (!fileStatus[i] && !el.IsLinkOnly) { RemoveFile(i); } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
private void handleLinkOnlyElements() { try { for (int i = 0; i < elements.Count; i++) { IPFSElement el = ((IPFSElement)elements[i]); if (el.IsLinkOnly && !el.Active) { new Thread(delegate() { el.Active = true; string output = ExecuteCommand("pin add " + el.Hash, true); if (output.Equals("pinned " + el.Hash + " recursively\n")) { ShowNotification("File Pinned!", System.Drawing.SystemIcons.Information, System.Windows.Forms.ToolTipIcon.Info, 5000); } if (File.Exists(jsonFilePath)) { string json = JsonConvert.SerializeObject(elements); File.SetAttributes(jsonFilePath, FileAttributes.Normal); File.WriteAllText(jsonFilePath, json); File.SetAttributes(jsonFilePath, FileAttributes.Hidden); } }).Start(); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
private void OpenFolderLocation(int index) { IPFSElement el = (IPFSElement)elements[index]; if (el.FileType.Equals(FileType.FOLDER)) { Process.Start("explorer.exe", el.Path); } else { Process.Start("explorer.exe", Path.GetDirectoryName(el.Path)); } }
private void RemoveFile(int index) { if (index < elements.Count) { IPFSElement el = ((IPFSElement)elements[index]); UnpinElement(el); objectListView1.RemoveObject(elements[index]); elements.RemoveAt(index); if (File.Exists(jsonFilePath)) { string json = JsonConvert.SerializeObject(elements); File.SetAttributes(jsonFilePath, FileAttributes.Normal); File.WriteAllText(jsonFilePath, json); File.SetAttributes(jsonFilePath, FileAttributes.Hidden); } } }
private void SetHyperLinkToClipboard(int index) { IPFSElement el = (IPFSElement)elements[index]; Clipboard.SetText("https://ipfs.io/ipfs/" + el.Hash); var notification = new System.Windows.Forms.NotifyIcon() { Visible = true, Icon = System.Drawing.SystemIcons.Information, BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info, BalloonTipText = "Link copied to Clipboard" }; // Display for 5 seconds. notification.ShowBalloonTip(2000); Thread.Sleep(2500); // The notification should be disposed when you don't need it anymore, // but doing so will immediately close the balloon if it's visible. notification.Dispose(); }
private void InitializeListView() { this.objectListView1.ShowImagesOnSubItems = true; this.objectListView1.SmallImageList = new ImageList(); this.objectListView1.SmallImageList.ImageSize = new Size(35, 35); this.objectListView1.SmallImageList.Images.Add(Resources.File); this.objectListView1.SmallImageList.Images.Add(Resources.Folder); this.objectListView1.SmallImageList.Images.Add(Resources.Hyperlink); this.objectListView1.SmallImageList.Images.Add(Resources.Open); this.objectListView1.SmallImageList.Images.Add(Resources.Remove); this.objectListView1.SmallImageList.Images.Add(Resources.ToggleOn); this.objectListView1.SmallImageList.Images.Add(Resources.ToggleOff); this.objectListView1.CellClick += (sender, args) => { switch (args.ColumnIndex) { case 2: ToggleActiveState(args.RowIndex); break; case 3: SetHyperLinkToClipboard(args.RowIndex); break; case 4: OpenFolderLocation(args.RowIndex); break; case 5: RemoveFile(args.RowIndex); break; } ; }; this.IconCol.ImageGetter = delegate(object rowObject) { IPFSElement el = (IPFSElement)rowObject; if (el.FileType.Equals(FileType.FILE)) { return(0); } else { return(1); } }; this.ActiveCol.ImageGetter = delegate(object rowObject) { IPFSElement el = (IPFSElement)rowObject; if (el.Active) { return(5); } else { return(6); } }; this.GetHyperlink.ImageGetter = delegate(object rowObject) { return(2); }; this.OpenFolder.ImageGetter = delegate(object rowObject) { return(3); }; this.Remove.ImageGetter = delegate(object rowObject) { return(4); }; parseIPFSObjects(); InitTimer(Properties.Settings.Default.RefreshRate); }