void updateWinTheme(WinTheme winTheme) { //find old file string themePath = findWinThemeFile(winTheme.name);; //delete old file if (themePath != "not_found") File.Delete(themePath); //apply theme (creating a new file) applyWinTheme(winTheme, true); ////delete old file //if (themePath != "not_found") // File.Delete(themePath); }
void applyWinTheme(WinTheme winTheme, bool alwaysCreateNewTheme) { //check if current wallpaper directory has at least 1 wallpaper //if it doesn't then the theme will fail to apply if (Directory.GetFiles(Application.StartupPath + "\\walls_current").Length == 0) { //create temp. wallpaper Image wall = new Bitmap(1024, 768); Graphics gfx = Graphics.FromImage(wall); gfx.FillRectangle(SystemBrushes.Control, 0, 0, 1024, 768); gfx.DrawString("This is a temporary wallpaper which you should not see.", SystemFonts.DefaultFont, SystemBrushes.ControlText, 0, 0); gfx.DrawString("If it persists check that you have properly configured Wallcreeper.", SystemFonts.DefaultFont, SystemBrushes.ControlText, 0, 15); gfx.DrawString("Probably you have no active wallpaper themes or, if you use online sources, perhaps your Internet connection is down?", SystemFonts.DefaultFont, SystemBrushes.ControlText, 0, 30); gfx.DrawString("Also try restarting Wallcreeper, or disabling the option to use Windows Vista/7 wallpaper manager.", SystemFonts.DefaultFont, SystemBrushes.ControlText, 0, 45); wall.Save(Application.StartupPath + "\\walls_current\\temp.jpg"); } if (!alwaysCreateNewTheme) { //does theme already exist? string themePath = findWinThemeFile(winTheme.name); if (themePath != "not_found") { runTheme(new FileInfo(themePath), false); return; } } //otherwise, create new theme file FileInfo themeFile = new FileInfo(Application.StartupPath + "\\" + winTheme.name + ".theme"); if (themeFile.Exists) themeFile.Delete(); StreamReader fRdr = new StreamReader(Application.StartupPath + "\\template.theme"); string themeContents = fRdr.ReadToEnd(); fRdr.Close(); //convert to win7 color format string color = ""; string[] temp; foreach (string win7Color in win7Colors) { temp = win7Color.Split('='); if (temp[0] == winTheme.color) { color = temp[1]; break; } } if (color == "" && winTheme.color.Contains('-')) { //convert from rgb temp = winTheme.color.Split('-'); color = "0X77" + int.Parse(temp[0]).ToString("X").PadRight(2, '0') + int.Parse(temp[1]).ToString("X").PadRight(2, '0') + int.Parse(temp[2]).ToString("X").PadRight(2, '0'); } themeContents = themeContents.Replace("%WALL_DIR%", Application.StartupPath + "\\walls_current").Replace("%REFRESHRATE%", getRefreshPeriod().ToString()).Replace("%NAME%", winTheme.name).Replace("%STYLE%", @"%SystemRoot%\resources\Themes\" + winTheme.style).Replace("%COLOR%", color).Replace("%SOUNDS%", winTheme.sounds).Replace("%SSAVER%", winTheme.ssaver); StreamWriter fWrt = themeFile.CreateText(); fWrt.Write(themeContents); fWrt.Close(); runTheme(themeFile, true); }