示例#1
0
        static void Main(string[] args)
        {
            string vsVersion = SharedFunc.vsVersion;

            using (FileStream fs = new FileStream("reg.iss", FileMode.Open))
                using (StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("gb2312")))
                    using (FileStream nfs = new FileStream("newreg.iss", FileMode.Create))
                        using (StreamWriter sw = new StreamWriter(nfs, Encoding.UTF8))
                        {
                            do
                            {
                                string line = sr.ReadLine();
                                if (line.Contains("[Code]"))
                                {
                                    break;
                                }
                                if (!SharedFunc.isValidPath(line))
                                {
                                    continue;
                                }

                                line = SharedFunc.pathReplace(vsVersion, line);

                                try
                                {
                                    string strValueName = "";
                                    string strValueData = "";
                                    string beforeAll    = "";
                                    if (line.Contains(" ValueName: ") && line.Contains(" ValueData: "))
                                    {
                                        beforeAll = line.Split(
                                            new string[] { " ValueName: " }, StringSplitOptions.None)[0];
                                        strValueName = line.Split(
                                            new string[] { " ValueName: " }, StringSplitOptions.None)[1]
                                                       .Split(
                                            new string[] { " ValueData: " }, StringSplitOptions.None)[0]
                                                       .TrimEnd(new char[] { ';' });
                                        strValueData = line.Split(
                                            new string[] { " ValueData: " }, StringSplitOptions.None)[1]
                                                       .Split(
                                            new string[] { " Flags: " }, StringSplitOptions.None)[0]
                                                       .TrimEnd(new char[] { ';' });
                                    }
                                    else if ((!line.Contains(" ValueName: ")) && line.Contains(" ValueData: "))
                                    {
                                        beforeAll = line.Split(
                                            new string[] { " ValueData: " }, StringSplitOptions.None)[0];
                                        strValueName = "";
                                        strValueData = line.Split(
                                            new string[] { " ValueData: " }, StringSplitOptions.None)[1]
                                                       .Split(
                                            new string[] { " Flags: " }, StringSplitOptions.None)[0]
                                                       .TrimEnd(new char[] { ';' });
                                    }
                                    else if (line.Contains(" ValueName: ") && (!line.Contains(" ValueData: ")))
                                    {
                                        beforeAll = line.Split(
                                            new string[] { " ValueName: " }, StringSplitOptions.None)[0];
                                        strValueName = line.Split(
                                            new string[] { " ValueName: " }, StringSplitOptions.None)[1]
                                                       .Split(
                                            new string[] { " Flags: " }, StringSplitOptions.None)[0]
                                                       .TrimEnd(new char[] { ';' });
                                        strValueData = "";
                                    }
                                    else if ((!line.Contains(" ValueName: ")) && (!line.Contains(" ValueData: ")))
                                    {
                                        throw new Exception();
                                    }

                                    string afterAll = line.Split(
                                        new string[] { " Flags: " }, StringSplitOptions.None)[1];

                                    if (strValueName.StartsWith(@"""") &&
                                        strValueName.EndsWith(@""""))
                                    {
                                        strValueName = strValueName.Substring(1, strValueName.Length - 2);
                                    }

                                    if (strValueData.StartsWith(@"""") &&
                                        strValueData.EndsWith(@""""))
                                    {
                                        strValueData = strValueData.Substring(1, strValueData.Length - 2);
                                    }

                                    if (strValueData.Contains("{break}"))
                                    {
                                        strValueData = strValueData.Replace("{break}", "{somethingthatwillneverappearinanyregfiles}");
                                        strValueData = strValueData.Replace("{", "{{");
                                        strValueData = strValueData.Replace("{{somethingthatwillneverappearinanyregfiles}", "{break}");
                                    }

                                    string newline = string.Format("{0} ValueName: \"{1}\"; ValueData: \"{2}\"; Flags: {3}"
                                                                   , beforeAll
                                                                   , strValueName
                                                                   , strValueData
                                                                   , afterAll);

                                    if (newline.Contains(" SubKey: ") && newline.Contains(" ValueType: "))
                                    {
                                        newline = newline.Insert(newline.IndexOf("SubKey:") + 8, "\"");
                                        newline = newline.Insert(newline.IndexOf("ValueType:") - 2, "\"");
                                    }

                                    if (newline.Contains("Wow6432Node"))
                                    {
                                        newline = newline + "; Check: IsWin64;";
                                    }

                                    sw.WriteLine(newline);
                                }
                                catch (Exception)
                                {
                                    sw.WriteLine(line);
                                }
                            }while (!sr.EndOfStream);
                            Console.WriteLine("Completed.");
                            Console.ReadLine();
                        }
        }
示例#2
0
        static void Main(string[] args)
        {
            string vsName       = SharedFunc.vsName;
            string vsVersion    = SharedFunc.vsVersion;
            string programFiles = SharedFunc.programFiles;

            string[] files = Directory.GetFiles(".", "*.lnk", SearchOption.AllDirectories);

            using (FileStream nfs = new FileStream("icons.iss", FileMode.Create))
                using (StreamWriter sw = new StreamWriter(nfs, Encoding.UTF8))
                {
                    sw.WriteLine("[Icons]");

                    foreach (string file in files)
                    {
                        ProcessStartInfo info = new ProcessStartInfo(
                            "lnk_parser_cmd.exe"
                            , string.Format("-w \"{0}\"", file));
                        info.CreateNoWindow = true;
                        info.WindowStyle    = ProcessWindowStyle.Hidden;
                        Process proc = new Process();
                        proc.StartInfo = info;
                        proc.Start();
                        proc.WaitForExit();

                        string csvFile = Directory.GetFiles(".", "*.htm", SearchOption.TopDirectoryOnly)[0];
                        using (FileStream fs = new FileStream(csvFile, FileMode.Open))
                            using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
                            {
                                string          html       = sr.ReadLine();
                                string          comment    = "";
                                string          arguments  = "";
                                string          path       = "";
                                string          workingdir = "";
                                MatchCollection mc;

                                string name = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file));

                                mc = Regex.Matches(html, "Comment \\(UNICODE\\)\\</div\\>\\<div id=\\\"d\\\"\\>(.*?)\\</div\\>");
                                if (mc.Count != 0)
                                {
                                    comment = mc[0].Groups[1].Value;
                                }

                                mc = Regex.Matches(html, "Arguments \\(UNICODE\\)\\</div\\>\\<div id=\\\"d\\\"\\>(.*?)\\</div\\>");
                                if (mc.Count != 0)
                                {
                                    arguments = mc[0].Groups[1].Value;
                                }

                                mc = Regex.Matches(html, "Local path \\(ASCII\\)\\</div\\>\\<div id=\\\"d\\\"\\>(.*?)\\</div\\>");
                                if (mc.Count != 0)
                                {
                                    path = mc[0].Groups[1].Value;
                                }

                                path = path.Replace(@"C:\Windows\System32\cmd.exe", "%comspec%");
                                mc   = Regex.Matches(html, "Working Directory \\(UNICODE\\)\\</div\\>\\<div id=\\\"d\\\"\\>(.*?)\\</div\\>");
                                if (mc.Count != 0)
                                {
                                    workingdir = mc[0].Groups[1].Value;
                                }

                                string line = string.Format(@"Name: ""{0}""; FileName: ""{1}""; Parameters: ""{2}""; WorkingDir: ""{3}""; Comment: ""{4}""; "
                                                            , name.Replace(@".\ProgramData\Microsoft\Windows\Start Menu\Programs", "{commonprograms}")
                                                            .Replace(@".\Visual Studio " + vsName, "{src}")
                                                            .Replace(@".\" + programFiles + @"\Microsoft Visual Studio " + vsVersion, "{src}")
                                                            , path
                                                            , arguments.Replace("\"", "\"\"")
                                                            , workingdir
                                                            , comment.Replace("\"", "\"\"")
                                                            );

                                line = SharedFunc.pathReplace(vsVersion, line);

                                sw.WriteLine(line);
                            }
                        File.Delete(csvFile);
                    }
                }
        }