Exemplo n.º 1
0
        private void Patch_Click(object sender, RoutedEventArgs e)
        {
            string path = SelectPath();

            if (path == null)
            {
                return;
            }
            if (isSDVExe(path) || EnsureSDVExe(path))
            {
                try
                {
                    FileVersionInfo SelectedVersion = FileVersionInfo.GetVersionInfo(path);
                    Stream          source          = new FileStream(path, FileMode.Open);
                    if (Program.patchData.version != SelectedVersion.FileVersion)
                    {
                        Program.logger.Log("PatchData Version: {0}\n Selected Version: {1}\n Selected Path: {2}",
                                           ConsoleLogger.LogLevel.Warn,
                                           Program.patchData.version,
                                           SelectedVersion.FileVersion,
                                           path);
                        Desc.Text = helper.GetString("L_Patch_ExeVersion", Program.patchData.version);
                        return;
                    }
                    if (!Program.CheckSHA1(Program.patchData.Source_SHA1, source))
                    {
                        Desc.Text = helper.GetString("L_Patch_ExeSHA1", Program.patchData.version);
                        return;
                    }
                    Stream dest = PatchHelper.GetPatched(source, Program.patchData.patch);
                    if (!Program.CheckSHA1(Program.patchData.Dest_SHA1, dest))
                    {
                        Desc.Text = helper.GetString("L_Patch_Fail_SHA1", Program.patchData.version);
                        return;
                    }
                    string destDict  = Path.GetDirectoryName(path);
                    string destName  = "Stardew Valley_Patched.exe";
                    string finalPath = Path.Combine(destDict, destName);
                    StreamHelper.WriteFile(dest, finalPath);
                    Program.ExtractDlls(destDict);
                    Desc.Text    = helper.GetString("L_Patch_Done", destName);
                    Command.Text = string.Format("\"{0}\" %command%", finalPath);
                    source.Close();
                }
                catch (Exception ex)
                {
                    Desc.Text = helper.GetString("L_Patch_Fail");
                    Program.logger.Log(ex.Message, ConsoleLogger.LogLevel.Error);
                    Program.logger.Log(ex.StackTrace, ConsoleLogger.LogLevel.Error);
                }
            }
        }
Exemplo n.º 2
0
        public PatchData(string origin, string dest, string version)
        {
            this.version = version;
            byte[] b_ori  = File.ReadAllBytes(origin);
            byte[] b_dest = File.ReadAllBytes(dest);
            Source_SHA1 = SHA1.Create().ComputeHash(b_ori);
            Dest_SHA1   = SHA1.Create().ComputeHash(b_dest);

            Stream patch = PatchHelper.CreatePatch(b_ori, b_dest);

            patch.Position = 0;//reset
            this.patch     = new byte[patch.Length];
            patch.Read(this.patch, 0, (int)patch.Length);
        }
Exemplo n.º 3
0
 private static void PatchConsole(string path)
 {
     try
     {
         FileVersionInfo SelectedVersion = FileVersionInfo.GetVersionInfo(path);
         Stream          source          = new FileStream(path, FileMode.Open);
         if (patchData.version != SelectedVersion.FileVersion)
         {
             logger.Log("PatchData Version: {0}\n Selected Version: {1}\n Selected Path: {2}",
                        ConsoleLogger.LogLevel.Warn,
                        patchData.version,
                        SelectedVersion.FileVersion,
                        path);
             logger.LogTrans("L_Patch_ExeVersion", ConsoleLogger.LogLevel.Warn, patchData.version);
             return;
         }
         if (!CheckSHA1(patchData.Source_SHA1, source))
         {
             logger.LogTrans("L_Patch_ExeSHA1", ConsoleLogger.LogLevel.Warn, patchData.version);
             return;
         }
         Stream dest = PatchHelper.GetPatched(source, patchData.patch);
         if (!CheckSHA1(patchData.Dest_SHA1, dest))
         {
             logger.LogTrans("L_Patch_Fail_SHA1", ConsoleLogger.LogLevel.Warn, patchData.version);
             return;
         }
         string destDict  = Path.GetDirectoryName(path);
         string destName  = "Stardew Valley_Patched.exe";
         string finalPath = Path.Combine(destDict, destName);
         StreamHelper.WriteFile(dest, finalPath);
         ExtractDlls(destDict);
         logger.LogTrans("L_Patch_Done", ConsoleLogger.LogLevel.Info, destName);
         logger.Log(string.Format("\"{0}\" %command%", finalPath), ConsoleLogger.LogLevel.Warn);
         source.Close();
     }
     catch (Exception ex)
     {
         logger.LogTrans("L_Patch_Fail");
         logger.Log(ex.Message, ConsoleLogger.LogLevel.Error);
         logger.Log(ex.StackTrace, ConsoleLogger.LogLevel.Error);
     }
 }