Example #1
0
        private static void ProcessSection(Section s)
        {
            foreach (Section child in s.Children)
            {
                ProcessSection(child);
            }

            foreach (String command in s.Commands)
            {
                if (command.StartsWith("!insertmacro InstallFile"))
                {
                    String[] parts = SplitIntoPartsTakingStringsIntoAccount(command, ' ');
                    if (parts.Length != 5)
                    {
                        throw new Exception("invalid number of parts");
                    }

                    ModifyFile f = new ModifyFile();
                    f.Filename     = parts[3].Trim('"');
                    f.FileLocation = parts[4].Trim('"');

                    f.CompleteFilename = GetCompleteFilename(f.FileLocation, f.Filename);

                    String dirContainingResHackerBatchStr = GetDirContainingResHackerBatch(f.CompleteFilename);

                    DirectoryInfo dirContainingResHackerBatch = new DirectoryInfo(dirContainingResHackerBatchStr);

                    ProcessFile(dirContainingResHackerBatch, f);

                    s.FilesToModify.Add(f);
                }
            }
        }
Example #2
0
        private static void ProcessFile(DirectoryInfo folder, ModifyFile f)
        {
            // open the file's reshacker script

            String fn = Path.Combine(folder.FullName, folder.Name + ".txt");

            if (!File.Exists(fn))
            {
                throw new FileNotFoundException("", fn);
            }

            StreamReader rdr = new StreamReader(fn);
            String       line;

            while ((line = rdr.ReadLine()) != null)
            {
                line = line.Trim();

                if (!line.StartsWith("-"))
                {
                    continue;
                }

                // insert a comma after the command
                line = line.Substring(0, line.IndexOf(' ')) + ", " + line.Substring(line.IndexOf(' '));

                String[] parts = line.Split(',');
                if (parts.Length != 5 && parts.Length != 4)
                {
                    throw new Exception("invalid number of parts");
                }

                String currentDirRelativeToLoc = folder.FullName.Replace(_nsiFilesDirectory, "");

                Operation o = new Operation();
                o.Op           = parts[0].Trim('"', ' ');
                o.Filename     = currentDirRelativeToLoc + parts[1].Trim('"', ' ').Replace("Resources\\" + folder.Name, "");
                o.ResourceType = parts[2].Trim('"', ' ');
                if (parts.Length >= 4)
                {
                    o.ResourceName = parts[3].Trim('"', ' ');
                }
                if (parts.Length == 5)
                {
                    o.ResourceLang = parts[4].Trim('"', ' ');
                }

                f.Operations.Add(o);
            }
        }