Exemple #1
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Logger.Debug(Methods.MethodFullName("Downloader", Thread.CurrentThread.ManagedThreadId.ToString(), this.Language.ToString()));

            if (UserSettings.BypassTranslationDateCheck || Methods.HasNewTranslations(this.Language) || Methods.IsTranslationOutdated(this.Language))
            {
                SWFileManager.LoadFileConfiguration(this.Language);
            }
            else
            {
                throw new Exception(StringLoader.GetText("exception_already_latest_translation", Methods.DateToLocalString(this.Language.LastUpdate)));
            }
        }
Exemple #2
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            this.Worker.ReportProgress((int)State.Prepare);

            if (this.PlaceTranslations)
            {
                Logger.Debug(Methods.MethodFullName("GameStart", Thread.CurrentThread.ManagedThreadId.ToString(), this.Language.ApplyingRegionId, this.Language.ToString()));

                SWFileManager.LoadFileConfiguration(this.Language);

                if (IsTranslationOutdatedOrMissing(this.Language))
                {
                    e.Result = true; // call force patch in completed event
                    return;
                }

                if (UserSettings.WantToPatchExe)
                {
                    string regionId           = this.Language.ApplyingRegionId == "jpc" ? "jp" : this.Language.ApplyingRegionId;
                    string regionFolder       = this.Language.ApplyingRegionFolder == "jpc" ? "jp" : this.Language.ApplyingRegionFolder;
                    string gameExePath        = Path.Combine(UserSettings.GamePath, Methods.GetGameExeName(regionId));
                    string gameExePatchedPath = Path.Combine(UserSettings.PatcherPath, regionId, Methods.GetGameExeName(regionId));
                    string backupFilePath     = Path.Combine(this.Language.BackupPath, Methods.GetGameExeName(regionId));

                    if (!File.Exists(gameExePatchedPath))
                    {
                        byte[] gameExeBytes = File.ReadAllBytes(gameExePath);

                        Methods.PatchExeFile(gameExeBytes, gameExePatchedPath, Urls.TranslationGitHubHome + regionFolder + '/' + Strings.IniName.BytesToPatch);
                    }

                    BackupAndPlaceFile(gameExePath, gameExePatchedPath, backupFilePath);
                }

                Process clientProcess = null;
                if (UserSettings.WantToLogin)
                {
                    string regionId = this.Language.ApplyingRegionId;
                    switch (regionId)
                    {
                    case "jp":
                        StartHangeJP(() => BackupAndPlaceFiles(this.Language));

                        this.Worker.ReportProgress((int)State.WaitClient);
                        while (true)
                        {
                            if (this.Worker.CancellationPending)
                            {
                                e.Cancel = true;
                                return;
                            }

                            clientProcess = GetProcess(Methods.GetGameExeName(regionId));

                            if (clientProcess == null)
                            {
                                Thread.Sleep(1000);
                            }
                            else
                            {
                                break;
                            }
                        }

                        break;

                    case "gjp":
                        StartGamecomJP(() => BackupAndPlaceFiles(this.Language));

                        this.Worker.ReportProgress((int)State.WaitClient);
                        while (true)
                        {
                            if (this.Worker.CancellationPending)
                            {
                                e.Cancel = true;
                                return;
                            }

                            clientProcess = GetProcess(Methods.GetGameExeName(regionId));

                            if (clientProcess == null)
                            {
                                Thread.Sleep(1000);
                            }
                            else
                            {
                                break;
                            }
                        }

                        break;

                    case "kr":
                        StartStoveKR(() => BackupAndPlaceFiles(this.Language));

                        this.Worker.ReportProgress((int)State.WaitClient);
                        while (true)
                        {
                            if (this.Worker.CancellationPending)
                            {
                                e.Cancel = true;
                                return;
                            }

                            clientProcess = GetProcess(Methods.GetGameExeName(regionId));

                            if (clientProcess == null)
                            {
                                Thread.Sleep(1000);
                            }
                            else
                            {
                                break;
                            }
                        }

                        break;

                    case "nkr":
                        Methods.RegionDoesNotSupportLogin();

                        break;

                    case "jpc":
                    case "gf":
                        Methods.RegionDoesNotSupportLogin();

                        break;

                    default:
                        throw new Exception(StringLoader.GetText("exception_region_unknown", regionId));
                    }
                }
                else if (Language.ApplyingRegionId == "jpc")
                {
                    BackupAndPlaceFiles(this.Language);
                    clientProcess = StartCustomGame();
                }
                else
                {
                    BackupAndPlaceFiles(this.Language);

                    this.Worker.ReportProgress((int)State.WaitClient);
                    while (true)
                    {
                        if (this.Worker.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }

                        clientProcess = GetProcess(Methods.GetGameExeName(this.Language.ApplyingRegionId));

                        if (clientProcess == null)
                        {
                            Thread.Sleep(1000);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                this.Worker.ReportProgress((int)State.WaitClose);
                clientProcess.WaitForExit();
            }
            else
            {
                Logger.Debug(Methods.MethodFullName("GameStart", Thread.CurrentThread.ManagedThreadId.ToString(), this.Language.ApplyingRegionId));

                if (UserSettings.WantToLogin)
                {
                    string regionId = this.Language.ApplyingRegionId;
                    switch (regionId)
                    {
                    case "jp":
                        StartHangeJP();
                        e.Cancel = true;

                        break;

                    case "gjp":
                        StartGamecomJP();
                        e.Cancel = true;

                        break;

                    case "jpc":
                        StartCustomGame();
                        e.Cancel = true;

                        break;

                    case "kr":
                        StartStoveKR();
                        e.Cancel = true;

                        break;

                    case "nkr":
                        Methods.RegionDoesNotSupportLogin();

                        break;

                    case "gf":
                        Methods.RegionDoesNotSupportLogin();

                        break;

                    default:
                        throw new Exception(StringLoader.GetText("exception_region_unknown", regionId));
                    }
                }
                else
                {
                    throw new Exception(StringLoader.GetText("exception_not_login_option"));
                }
            }
        }
Exemple #3
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            this.Worker.ReportProgress((int)State.Prepare);

            if (this.PlaceTranslations)
            {
                Logger.Debug(Methods.MethodFullName("GameStart", Thread.CurrentThread.ManagedThreadId.ToString(), this.Language.ApplyingRegionId, this.Language.ToString()));

                SWFileManager.LoadFileConfiguration(this.Language);

                if (IsTranslationOutdatedOrMissing(this.Language))
                {
                    e.Result = true; // call force patch in completed event
                    return;
                }

                if (UserSettings.WantToPatchExe)
                {
                    string regionId           = this.Language.ApplyingRegionId;
                    string gameExePath        = Path.Combine(UserSettings.GamePath, Methods.GetGameExeName(regionId));
                    string gameExePatchedPath = Path.Combine(UserSettings.PatcherPath, regionId, Methods.GetGameExeName(regionId));
                    string backupFilePath     = Path.Combine(this.Language.BackupPath, Methods.GetGameExeName(regionId));

                    if (!File.Exists(gameExePatchedPath))
                    {
                        byte[] gameExeBytes = File.ReadAllBytes(gameExePath);

                        Methods.PatchExeFile(gameExeBytes, gameExePatchedPath, Urls.TranslationGitHubHome + regionId + '/' + Strings.IniName.BytesToPatch);
                    }

                    BackupAndPlaceFile(gameExePath, gameExePatchedPath, backupFilePath);
                }

                Process          clientProcess = null;
                ProcessStartInfo startInfo     = null;
                if (UserSettings.WantToLogin)
                {
                    string regionId = this.Language.ApplyingRegionId;
                    switch (regionId)
                    {
                    case "jp":
                        Methods.RegionDoesNotSupportLogin();     // TODO: jp login?
                        break;
                        using (var client = new MyWebClient())
                        {
                            HangameLogin(client);
                            string[] gameStartArgs = GetGameStartArguments(client);

                            startInfo = new ProcessStartInfo
                            {
                                UseShellExecute  = true,
                                Verb             = "runas",
                                Arguments        = String.Join(" ", gameStartArgs.Select(s => "\"" + s + "\"")),
                                WorkingDirectory = UserSettings.GamePath,
                                FileName         = Methods.GetGameExeName(regionId)
                            };
                        }

                        BackupAndPlaceFiles(this.Language);

                        clientProcess = Process.Start(startInfo);

                        break;

                    case "kr":
                        LoginStartKR();

                        this.Worker.ReportProgress((int)State.WaitClient);
                        while (true)
                        {
                            if (this.Worker.CancellationPending)
                            {
                                e.Cancel = true;
                                return;
                            }

                            clientProcess = GetProcess(Methods.GetGameExeName(regionId));

                            if (clientProcess == null)
                            {
                                Thread.Sleep(1000);
                            }
                            else
                            {
                                break;
                            }
                        }

                        break;

                    case "nkr":
                        Methods.RegionDoesNotSupportLogin();
                        break;
                    }
                }
                else
                {
                    BackupAndPlaceFiles(this.Language);

                    this.Worker.ReportProgress((int)State.WaitClient);
                    while (true)
                    {
                        if (this.Worker.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }

                        clientProcess = GetProcess(Methods.GetGameExeName(this.Language.ApplyingRegionId));

                        if (clientProcess == null)
                        {
                            Thread.Sleep(1000);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                this.Worker.ReportProgress((int)State.WaitClose);
                clientProcess.WaitForExit();
            }
            else
            {
                Logger.Debug(Methods.MethodFullName("GameStart", Thread.CurrentThread.ManagedThreadId.ToString(), this.Language.ApplyingRegionId));

                if (UserSettings.WantToLogin)
                {
                    switch (this.Language.ApplyingRegionId)
                    {
                    case "jp":
                        Methods.RegionDoesNotSupportLogin();     // TODO: jp login?
                        break;
                        StartRawJP();
                        e.Cancel = true;

                        break;

                    case "kr":
                        StartRawKR();
                        e.Cancel = true;

                        break;

                    case "nkr":
                        Methods.RegionDoesNotSupportLogin();
                        break;
                    }
                }
                else
                {
                    throw new Exception(StringLoader.GetText("exception_not_login_option"));
                }
            }
        }