public MainWindow() { InitializeComponent(); if (System.IO.File.Exists(XMLList)) { generatedXMLs = TextListConverter.ReadFile(XMLList); } }
//===== // Generate configure files for all apps in start menu private void GenXMLs() { out2box("Start scanning all start menu items...\n"); allLnks.Clear(); allLnkTargets.Clear(); ScanLnks(new DirectoryInfo(pathForAllUsers)); ScanLnks(new DirectoryInfo(pathForCurentUser)); out2box("Start generating colors...\n"); foreach (string targetFile in allLnkTargets) { if (!System.IO.File.Exists(targetFile)) { continue; } Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(targetFile); Bitmap bitmap = icon.ToBitmap(); int h = bitmap.Height; int w = bitmap.Width; int pixelCount = h * w; int meanR = 0, meanG = 0, meanB = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { meanR += bitmap.GetPixel(i, j).R; meanG += bitmap.GetPixel(i, j).G; meanB += bitmap.GetPixel(i, j).B; } } meanR /= pixelCount; meanG /= pixelCount; meanB /= pixelCount; string hex = meanR.ToString("X2") + meanG.ToString("X2") + meanB.ToString("X2"); double grayLevel = (0.299 * meanR + 0.587 * meanG + 0.114 * meanB) / 255.0; string fgColor = grayLevel > 0.5 ? "dark" : "light"; WriteStyleXML(targetFile, fgColor, hex); } out2box("Writting XML list...\n"); TextListConverter.AppendFile(generatedXMLs, XMLList); }
private void RemoveXMLs() { out2box("Removing created XML files\n"); List <string> removed = new List <string>(); foreach (string xmlfile in generatedXMLs) { try { System.IO.File.Delete(xmlfile); removed.Add(xmlfile); } catch (Exception e) { out2box("Cannot delete: " + xmlfile + "\n", "red"); } } foreach (string xmlfile in removed) { generatedXMLs.Remove(xmlfile); } TextListConverter.WriteFile(generatedXMLs, XMLList); }