private static void AddSpecialFolder(Environment.SpecialFolder sf) { try { AddSpecialFolder(sf.ToString(), Environment.GetFolderPath(sf)); } catch { } }
public static bool IsEnvironment(Environment env) { return ConfigurationManager.AppSettings["Environment"] == env.ToString(); }
public static void RemoveShortcut(Environment.SpecialFolder directory, String subdir = "") { try { log.Debug("RemoveShortcut: directory=" + directory.ToString() + "; subdir=" + subdir); if (subdir != "") subdir = "\\" + subdir; String shortcutDir = Environment.GetFolderPath(directory) + subdir; if (!System.IO.Directory.Exists(shortcutDir)) { log.Info("Failed to delete shortcut in \"" + shortcutDir + "\" - directory does not exist."); return; } foreach (String file in System.IO.Directory.GetFiles(shortcutDir)) { if (file.EndsWith("\\OutlookGoogleCalendarSync.lnk") || //legacy name <=v2.1.0.0 file.EndsWith("\\" + Application.ProductName + ".lnk")) { System.IO.File.Delete(file); log.Info("Deleted shortcut in \"" + shortcutDir + "\""); break; } } } catch (System.Exception ex) { log.Warn("Problem trying to remove legacy Start Menu shortcut."); log.Error(ex.Message); } }
//public static void AddShortcut(Environment.SpecialFolder directory, String subdir = "") { // log.Debug("AddShortcut: directory=" + directory.ToString() + "; subdir=" + subdir); // String appPath = Application.ExecutablePath; // if (subdir != "") subdir = "\\" + subdir; // String shortcutDir = Environment.GetFolderPath(directory) + subdir; // if (!System.IO.Directory.Exists(shortcutDir)) { // log.Debug("Creating directory " + shortcutDir); // System.IO.Directory.CreateDirectory(shortcutDir); // } // string shortcutLocation = System.IO.Path.Combine(shortcutDir, Application.ProductName + ".lnk"); // #region "Windows Script Host Object Model - 32bit only" // /* // IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); // IWshRuntimeLibrary.IWshShortcut shortcut = shell.CreateShortcut(shortcutLocation) as IWshRuntimeLibrary.WshShortcut; // shortcut.Description = "Synchronise Outlook and Google calendars"; // shortcut.IconLocation = appPath.ToLower().Replace("OutlookGoogleCalendarSync.exe", "icon.ico"); // shortcut.TargetPath = appPath; // shortcut.WorkingDirectory = Application.StartupPath; // shortcut.Save(); // */ // #endregion // #region "C:\Windows\System32\shell32.dll - works but only compiles in VSE 2010?!" // /* // System.IO.File.WriteAllBytes(shortcutLocation, new byte[] { }); // //Initialize a ShellLinkObject for that .lnk file // Shell32.Shell shl = new Shell32.ShellClass(); // Shell32.Folder dir = shl.NameSpace(shortcutDir); // Shell32.FolderItem itm = dir.Items().Item(Application.ProductName + ".lnk"); // Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink; // lnk.Path = appPath; // lnk.Description = "Synchronise Outlook and Google calendars"; // lnk.WorkingDirectory = Application.StartupPath; // lnk.SetIconLocation(appPath.ToLower().Replace("OutlookGoogleCalendarSync.exe", "icon.ico"), 0); // lnk.Save(shortcutLocation); // */ // #endregion // log.Info("Created shortcut in \"" + shortcutDir + "\""); //} public static Boolean CheckShortcut(Environment.SpecialFolder directory, String subdir = "") { log.Debug("CheckShortcut: directory=" + directory.ToString() + "; subdir=" + subdir); Boolean foundShortcut = false; if (subdir != "") subdir = "\\" + subdir; String shortcutDir = Environment.GetFolderPath(directory) + subdir; if (!System.IO.Directory.Exists(shortcutDir)) return false; foreach (String file in System.IO.Directory.GetFiles(shortcutDir)) { if (file.EndsWith("\\OutlookGoogleCalendarSync.lnk") || //legacy name <=v2.1.0.0 file.EndsWith("\\" + Application.ProductName + ".lnk")) { foundShortcut = true; break; } } return foundShortcut; }
public static void RemoveShortcut(Environment.SpecialFolder directory, String subdir = "") { log.Debug("RemoveShortcut: directory=" + directory.ToString() + "; subdir=" + subdir); if (subdir != "") subdir = "\\" + subdir; String shortcutDir = Environment.GetFolderPath(directory) + subdir; if (!System.IO.Directory.Exists(shortcutDir)) { log.Info("Failed to delete shortcut in \"" + shortcutDir + "\" - directory does not exist."); return; } foreach (String file in System.IO.Directory.GetFiles(shortcutDir)) { if (file.EndsWith("\\OutlookGoogleCalendarSync.lnk")) { System.IO.File.Delete(file); log.Info("Deleted shortcut in \"" + shortcutDir + "\""); break; } } }
public static void AddShortcut(Environment.SpecialFolder directory, String subdir = "") { log.Debug("AddShortcut: directory=" + directory.ToString() + "; subdir=" + subdir); String appPath = Application.ExecutablePath; if (subdir != "") subdir = "\\" + subdir; String shortcutDir = Environment.GetFolderPath(directory) + subdir; if (!System.IO.Directory.Exists(shortcutDir)) { log.Debug("Creating directory " + shortcutDir); System.IO.Directory.CreateDirectory(shortcutDir); } string shortcutLocation = System.IO.Path.Combine(shortcutDir, "OutlookGoogleCalendarSync.lnk"); IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = shell.CreateShortcut(shortcutLocation) as IWshRuntimeLibrary.WshShortcut; shortcut.Description = "Synchronise Outlook and Google calendars"; shortcut.IconLocation = appPath.ToLower().Replace("OutlookGoogleCalendarSync.exe", "icon.ico"); shortcut.TargetPath = appPath; shortcut.WorkingDirectory = Application.StartupPath; shortcut.Save(); log.Info("Created shortcut in \"" + shortcutDir + "\""); }
private static string GetDisplayName(Environment.SpecialFolder sf) { string path = Environment.GetFolderPath(sf, Environment.SpecialFolderOption.Create); if (Directory.Exists(path)) { return System.IO.Path.GetFileName(path); } return sf.ToString(); }
public Shortcut(Environment.SpecialFolder specialFolder) { var folder = new Folder(Environment.GetFolderPath(specialFolder)); name = folder.Name; command = folder.FullName; icon = new PluginIconLoader().Png(specialFolder.ToString()); }