Beispiel #1
0
 /// <summary>
 /// Save config to file
 /// </summary>
 public void SaveConfig()
 {
     try
     {
         Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
         config.AppSettings.Settings.Clear();
         // maybe one day I will use reflection to make this better
         config.AppSettings.Settings.Add("wpLandscape", wpLandscape);
         config.AppSettings.Settings.Add("wpPortrait", wpPortrait);
         config.AppSettings.Settings.Add("lcLandscape", lcLandscape);
         config.AppSettings.Settings.Add("lcPortrait", lcPortrait);
         config.AppSettings.Settings.Add("language", language);
         config.AppSettings.Settings.Add("reverse", reverse.ToString());
         config.AppSettings.Settings.Add("posWpLandscape", wpPosLandscape.ToString());
         config.AppSettings.Settings.Add("posWpPortrait", wpPosPortrait.ToString());
         config.AppSettings.Settings.Add("lastWidth", lastWidth.ToString());
         config.AppSettings.Settings.Add("lastHeight", lastHeight.ToString());
         config.AppSettings.Settings.Add("ver", ver.ToString());
         config.Save();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Fatal error: failed writing config file. Permission needed?\n严重错误:写入设置文件失败。请检查权限。", "", MessageBoxButton.OK, MessageBoxImage.Error);
         if (GeneralLogger.IsInitialized())
         {
             GeneralLogger.WriteLog("Failed writing config file, error:" + ex.Message, LogType.ERROR);
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// Set the autorun checkbox
 /// </summary>
 public static bool GetAutorunState()
 {
     try
     {
         RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
         object      v   = key.GetValue("co.logu.DWAS2", null);
         if (v != null)
         {
             string s = (string)v;
             return(string.Compare(s, Assembly.GetExecutingAssembly().Location) == 0);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         if (GeneralLogger.IsInitialized())
         {
             GeneralLogger.WriteLog("Get autorun state failed. error:" + ex.Message, LogType.ERROR);
         }
         return(false);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Set the picture position of Windows (by setting registry)
 /// </summary>
 /// <param name="p">target picture position</param>
 /// <returns>true if succeed, false otherwise</returns>
 public static bool SetDesktopPicPos(PicPos p)
 {
     try
     {
         RegistryKey reg = Registry.CurrentUser;
         reg = reg.OpenSubKey("Control Panel\\desktop", true);
         reg.SetValue("WallpaperStyle", ((int)p).ToString());
         reg.Close();
         return(true);
     }
     catch (Exception ex)
     {
         if (GeneralLogger.IsInitialized())
         {
             GeneralLogger.WriteLog("Set desktop picpos failed. error:" + ex.Message, LogType.ERROR);
         }
         return(false);
     }
 }
Beispiel #4
0
 public static bool SetAutorunState(bool autorun)
 {
     try
     {
         RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
         if (autorun)
         {
             key.SetValue("co.logu.DWAS2", Assembly.GetExecutingAssembly().Location);
         }
         else
         {
             key.DeleteValue("co.logu.DWAS2", false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         if (GeneralLogger.IsInitialized())
         {
             GeneralLogger.WriteLog("Set autorun state failed. error:" + ex.Message, LogType.ERROR);
         }
         return(false);
     }
 }