Esempio n. 1
0
        public Form1(string platformName)
        {
            m_locator = new ShenzhenLocator(platformName);
            InitializeComponent();

            this.label4.Text      = m_locator.GetUIString("LocateShenzhenFolder");
            this.label7.Text      = m_locator.GetUIString("SaveFilesHint");
            m_exeFolderField.Text = m_locator.FindShenzhenDirectory();
        }
Esempio n. 2
0
        public void Install()
        {
            sm_log.Info("Finding unpatched SHENZHEN I/O executable");
            string exePath = ShenzhenLocator.FindUnpatchedShenzhenExecutable(m_shenzhenDir);
            string exeDir  = Path.GetDirectoryName(exePath);

            if (Path.GetFileName(exePath).Equals("Shenzhen.exe", StringComparison.OrdinalIgnoreCase))
            {
                string backupPath = Path.Combine(exeDir, "Shenzhen.Unpatched.exe");
                sm_log.InfoFormat("Backing up unpatched executable \"{0}\" to \"{1}\"", exePath, backupPath);
                File.Copy(exePath, backupPath, overwrite: true);
            }

            string patchedPath = Path.Combine(exeDir, "Shenzhen.Patched.exe");

            if (File.Exists(patchedPath))
            {
                sm_log.InfoFormat("Deleting existing patched file \"{0}\"", patchedPath);
                File.Delete(patchedPath);
            }

            ApplyPatches(exePath, patchedPath);

            string targetPath = Path.Combine(exeDir, "Shenzhen.exe");

            if (File.Exists(targetPath))
            {
                // Rename the existing Shenzhen.exe before overwriting it, in case the user wants to roll back
                string timestamp  = DateTime.Now.ToString("yyyyMMdd-HHmmss", CultureInfo.InvariantCulture);
                string backupPath = Path.Combine(exeDir, Invariant($"Shenzhen.{timestamp}.exe"));
                sm_log.InfoFormat("Moving \"{0}\" to \"{1}\"", targetPath, backupPath);
                File.Move(targetPath, backupPath);
            }

            sm_log.InfoFormat("Moving \"{0}\" to \"{1}\"", patchedPath, targetPath);
            File.Move(patchedPath, targetPath);
        }