コード例 #1
0
 internal static void DeleteAllNotesShortcuts()
 {
     try
     {
         var desktop = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
         var shortcuts = desktop.GetFiles("*.lnk");
         var linksToDelete = new List<string>();
         var linksToSave = new List<string>();
         foreach (var f in shortcuts)
         {
             using (var link = new PNShellLink())
             {
                 link.Load(f.FullName);
                 if (
                     !string.Equals(link.Target, System.Windows.Forms.Application.ExecutablePath,
                         StringComparison.OrdinalIgnoreCase)) continue;
                 var args = link.Arguments;
                 if (!args.StartsWith("-i")) continue;
                 var arr = args.Split(' ');
                 if (arr.Length < 2) continue;
                 linksToDelete.Add(f.FullName);
                 linksToSave.Add(arr[1]);
             }
         }
         foreach (var s in linksToDelete)
         {
             File.Delete(s);
         }
         PNData.SaveNotesWithShortcuts(linksToSave);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #2
0
 internal static void DeleteNoteShortcut(string id)
 {
     try
     {
         var arguments = "-i " + id;
         var desktop = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
         var shortcuts = desktop.GetFiles("*.lnk");
         var fileToDelete = "";
         foreach (var f in shortcuts)
         {
             using (var link = new PNShellLink())
             {
                 link.Load(f.FullName);
                 if (
                     !string.Equals(link.Target, System.Windows.Forms.Application.ExecutablePath,
                         StringComparison.OrdinalIgnoreCase)) continue;
                 if (link.Arguments != arguments) continue;
                 fileToDelete = f.FullName;
                 break;
             }
         }
         if (fileToDelete.Length > 0)
         {
             File.Delete(fileToDelete);
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #3
0
 internal static void SaveAsShortcut(PNote note)
 {
     try
     {
         // create shortcut
         var counter = 1;
         var arguments = "-i " + note.ID;
         var pntargets = new List<string>();
         var desktop = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
         var shortcuts = desktop.GetFiles("*.lnk");
         //get all desktop shortcuts first
         foreach (var f in shortcuts)
         {
             using (var link = new PNShellLink())
             {
                 link.Load(f.FullName);
                 if (string.Equals(link.Target, System.Windows.Forms.Application.ExecutablePath, StringComparison.OrdinalIgnoreCase))
                 {
                     //collect shortcuts to PNotes.NET
                     pntargets.Add(f.FullName);
                 }
             }
         }
         var shortcutName = note.Name;
         while (true)
         {
             if (pntargets.Any(s =>
             {
                 var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(s);
                 return fileNameWithoutExtension != null && string.Equals(fileNameWithoutExtension, shortcutName, StringComparison.OrdinalIgnoreCase);
             }))
             {
                 counter++;
                 shortcutName = note.Name + "(" + counter + ")";
                 continue;
             }
             break;
         }
         foreach (var s in pntargets)
         {
             using (var link = new PNShellLink())
             {
                 link.Load(s);
                 if (link.Arguments == arguments)
                 {
                     //exit if there is shortcut to the current note
                     return;
                 }
             }
         }
         var shortcutFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" +
                            shortcutName + ".lnk";
         if (File.Exists(shortcutFile)) return;
         using (var link = new PNShellLink())
         {
             link.ShortcutFile = shortcutFile;
             link.Target = System.Windows.Forms.Application.ExecutablePath;
             link.WorkingDirectory = System.Windows.Forms.Application.StartupPath;
             link.IconPath = System.Windows.Forms.Application.ExecutablePath;
             link.IconIndex = 1;
             link.Arguments = arguments;
             link.Save();
         }
         if (PNStatic.Settings.GeneralSettings.CloseOnShortcut)
         {
             ShowHideSpecificNote(note, false);
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }