private void CopyFile(LogWindow log, string a, string b)
        {
            log.WriteNormal($"Copying ");
            log.WriteHighlight(a);
            log.WriteNormal($" to ");
            log.WriteHighlight(b);
            log.WriteNormal($"\n");

            System.IO.File.Copy(a, b, true);
        }
Exemple #2
0
        private void PatchComposer(object sender, EventArgs eventargs)
        {
            var oldLine = "<setting name=\"ComposerPro_LicensingService_Licensing\" serializeAs=\"String\">";
            var newLine = "<setting name=\"ComposerPro_LicensingService_Licensing\" serializeAs=\"0\">";

            var log = new LogWindow(MainWindow);

            log.WriteTrace("Asking for ComposerPro.exe.config location\n");

            OpenFileDialog open = new OpenFileDialog();

            open.Filter           = "Config Files|*.config";
            open.Title            = "Find Original ComposerPro.exe.config";
            open.InitialDirectory = "C:\\Program Files (x86)\\Control4\\Composer\\Pro";
            open.FileName         = "ComposerPro.exe.config";

            if (open.ShowDialog() != DialogResult.OK)
            {
                log.WriteError("Cancelled\n");
                return;
            }

            if (string.IsNullOrEmpty(open.FileName))
            {
                log.WriteError("Filename was invalid\n");
                return;
            }

            log.WriteNormal("Opening ");
            log.WriteHighlight($"{open.FileName}\n");

            var contents = System.IO.File.ReadAllText(open.FileName);

            if (!contents.Contains(oldLine))
            {
                log.WriteHighlight("Couldn't find the line - probably already patched??");
                return;
            }

            log.WriteHighlight($"Writing Backup..\n");
            System.IO.File.WriteAllText(open.FileName + $".backup-{DateTime.Now.ToString( "yyyy-dd-M--HH-mm-ss" )}", contents);

            log.WriteHighlight($"Writing New File..\n");
            contents = contents.Replace(oldLine, newLine);

            System.IO.File.WriteAllText(open.FileName, contents);
            log.WriteHighlight($"Done!\n");
        }
        int RunProcessPrintOutput(LogWindow log, string exe, string arguments)
        {
            log.WriteNormal(System.IO.Path.GetFileName(exe));
            log.WriteNormal(" ");
            log.WriteHighlight(arguments);
            log.WriteNormal("\n");

            ProcessStartInfo startInfo = new ProcessStartInfo(exe, arguments);

            startInfo.WorkingDirectory       = Environment.CurrentDirectory;
            startInfo.CreateNoWindow         = true;
            startInfo.UseShellExecute        = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;

            var process = System.Diagnostics.Process.Start(startInfo);

            log.WriteTrace(process.StandardOutput.ReadToEnd());
            log.WriteTrace(process.StandardError.ReadToEnd());

            process.WaitForExit();

            log.WriteTrace(process.StandardError.ReadToEnd());
            log.WriteTrace(process.StandardOutput.ReadToEnd());

            log.WriteNormal("\n");

            return(process.ExitCode);
        }
        private void PatchComposer(object sender, EventArgs eventargs)
        {
            var oldLine = @"  <system.net>
    <connectionManagement>
      <add address=""*"" maxconnection=""20"" />
    </connectionManagement>
  </system.net>";
            var newLine = @"   <system.net>
    <connectionManagement>
      <add address=""*"" maxconnection=""20"" />
    </connectionManagement>
    <defaultProxy>
      <proxy usesystemdefault=""false"" proxyaddress=""http://127.0.0.1:31337/"" bypassonlocal=""True""/>
    </defaultProxy>
  </system.net>

";

            var log = new LogWindow(MainWindow);

            log.WriteTrace("Asking for ComposerPro.exe.config location\n");

            OpenFileDialog open = new OpenFileDialog();

            open.Filter           = "Config Files|*.config";
            open.Title            = "Find Original ComposerPro.exe.config";
            open.InitialDirectory = "C:\\Program Files (x86)\\Control4\\Composer\\Pro";
            open.FileName         = "ComposerPro.exe.config";

            if (open.ShowDialog() != DialogResult.OK)
            {
                log.WriteError("Cancelled\n");
                return;
            }

            if (string.IsNullOrEmpty(open.FileName))
            {
                log.WriteError("Filename was invalid\n");
                return;
            }

            log.WriteNormal("Opening ");
            log.WriteHighlight($"{open.FileName}\n");

            var contents = System.IO.File.ReadAllText(open.FileName);

            if (!contents.Contains(oldLine))
            {
                log.WriteHighlight("Couldn't find the line - probably already patched??");
                return;
            }

            log.WriteHighlight($"Writing Backup..\n");
            System.IO.File.WriteAllText(open.FileName + $".backup-{DateTime.Now.ToString( "yyyy-dd-M--HH-mm-ss" )}", contents);

            log.WriteHighlight($"Writing New File..\n");
            contents = contents.Replace(oldLine, newLine);

            System.IO.File.WriteAllText(open.FileName, contents);
            log.WriteHighlight($"Done!\n");
        }
Exemple #5
0
        private void PatchComposer(object sender, EventArgs eventargs)
        {
            var log = new LogWindow(MainWindow);

            log.WriteTrace("Asking for ComposerPro.exe location\n");

            OpenFileDialog open = new OpenFileDialog();

            open.Filter           = "Executable Files|*.exe";
            open.Title            = "Find Original ComposerPro.exe";
            open.InitialDirectory = "C:\\Program Files (x86)\\Control4\\Composer\\Pro";
            open.FileName         = "ComposerPro.exe";

            if (open.ShowDialog() != DialogResult.OK)
            {
                log.WriteError("Cancelled\n");
                return;
            }

            if (string.IsNullOrEmpty(open.FileName))
            {
                log.WriteError("Filename was invalid\n");
                return;
            }

            log.WriteNormal("Opening ");
            log.WriteHighlight($"{open.FileName}\n");

            using (var val = AssemblyDefinition.ReadAssembly(open.FileName))
            {
                log.WriteTrace($"Finding \"Control4.ComposerPro.MainForm\"\n");

                var mainForm = val.MainModule.Types.SingleOrDefault(x => x.FullName == "Control4.ComposerPro.MainForm");
                if (mainForm == null)
                {
                    log.WriteError("Oops - couldn't find the class Control4.ComposerPro.MainForm\n");
                    return;
                }

                log.WriteNormal($"Found ");
                log.WriteHighlight($"{mainForm}\n");

                log.WriteTrace($"Finding \"ShowStartupOnFirstRun\"\n");

                var showStartupOnFirstRun = mainForm.Methods.SingleOrDefault(x => x.Name == "ShowStartupOnFirstRun");
                if (showStartupOnFirstRun == null)
                {
                    log.WriteError("Oops - couldn't find the method ShowStartupOnFirstRun (Maybe already patched?)\n");
                    return;
                }

                log.WriteNormal($"Found ");
                log.WriteHighlight($"{showStartupOnFirstRun}\n");

                log.WriteNormal($"Removing..");
                mainForm.Methods.Remove(showStartupOnFirstRun);
                log.WriteSuccess($" ..Done!\n");

                // TODO - Skip update check
                // TODO - Add info in window title
                // TODO - Fix dealeraccount.xml not found exception

                try
                {
                    var outFile = System.IO.Path.ChangeExtension(open.FileName, NewExtension);

                    //
                    // We might be re-patching for some reason, so delete the old one
                    //
                    if (System.IO.File.Exists(outFile))
                    {
                        System.IO.File.Delete(outFile);
                    }

                    log.WriteNormal($"Saving to ");
                    log.WriteHighlight($"{outFile}\n\n");

                    // Save the file
                    val.Write(outFile);

                    // We need to copy the config and manifest too, or we'll be missing a bunch of settings
                    log.WriteNormal($"Copying ");
                    log.WriteHighlight($"ComposerPro.exe.manifest");
                    log.WriteNormal($" to ");
                    log.WriteHighlight($"ComposerPro{NewExtension}.manifest\n");

                    System.IO.File.Copy($"{open.FileName}.manifest", $"{outFile}.manifest", true);

                    log.WriteNormal($"Copying ");
                    log.WriteHighlight($"ComposerPro.exe.config");
                    log.WriteNormal($" to ");
                    log.WriteHighlight($"ComposerPro{NewExtension}.config\n");

                    System.IO.File.Copy($"{open.FileName}.config", $"{outFile}.config", true);

                    // Create desktop shortcut
                    {
                        log.WriteNormal($"\nCreating Desktop Shortcut.. ");

                        var shortcutPath = $"{Environment.GetFolderPath( Environment.SpecialFolder.DesktopDirectory )}\\Composer Pro (Patched).url";

                        if (System.IO.File.Exists(shortcutPath))
                        {
                            System.IO.File.Delete(shortcutPath);
                        }

                        using (StreamWriter writer = new StreamWriter(shortcutPath))
                        {
                            var app = outFile.Replace('\\', '/');

                            writer.WriteLine("[InternetShortcut]");
                            writer.WriteLine($"URL=file:///{app.Replace( " ", "%20" )}");
                            writer.WriteLine("IconIndex=0");
                            writer.WriteLine("IconFile=" + app);
                            writer.Flush();
                        }

                        log.WriteSuccess($"done!\n");
                    }


                    log.WriteSuccess($"\nAll done - you can close this window!\n");
                }
                catch (UnauthorizedAccessException e)
                {
                    log.WriteError($"Exception - {e.Message}\n");
                }
            }
        }