Example #1
0
            public void Cs1GameInit()
            {
                int  CurrentProgress       = 0;
                int  TotalProgress         = 4;
                bool shouldAutoCloseWindow = true;

                try {
                    Progress.Message("Checking Sen1Launcher.exe...", CurrentProgress++, TotalProgress);
                    using (var fs = new HyoutaUtils.Streams.DuplicatableFileStream(Sen1LauncherPath)) {
                        SHA1 hash = ChecksumUtils.CalculateSHA1ForEntireStream(fs);
                        if (hash != new SHA1(0x8dde2b39f128179aul, 0x0beb3301cfd56a98ul, 0xc0f98a55u))
                        {
                            Progress.Error("Selected file does not appear to be Sen1Launcher.exe of version 1.6.");
                            Progress.Finish(false);
                            return;
                        }
                    }
                } catch (Exception ex) {
                    Progress.Error("Error while validating Sen1Launcher.exe: " + ex.Message);
                    Progress.Finish(false);
                    return;
                }

                try {
                    Path = System.IO.Path.GetDirectoryName(Sen1LauncherPath);
                    Progress.Message("Checking if we have encoding errors in filenames...", CurrentProgress++, TotalProgress);
                    if (FilenameFix.FixupIncorrectEncodingInFilenames(Path, 1, false, Progress))
                    {
                        if (!FilenameFix.FixupIncorrectEncodingInFilenames(Path, 1, true, Progress))
                        {
                            Progress.Error("Failed to fix encoding errors in filenames, attempting to proceed anyway...");
                            shouldAutoCloseWindow = false;
                        }
                    }
                    Progress.Message("Initializing patch data...", CurrentProgress++, TotalProgress);
                    var files = Sen1KnownFiles.Files;
                    Progress.Message("Initializing game data...", CurrentProgress++, TotalProgress);
                    var storageInit = FileModExec.InitializeAndPersistFileStorage(Path, files, Progress);
                    Storage = storageInit?.Storage;
                    if (storageInit == null || storageInit.Errors.Count != 0)
                    {
                        shouldAutoCloseWindow = false;
                    }
                } catch (Exception ex) {
                    Progress.Error("Error while initializing CS1 patch/game data: " + ex.Message);
                    Progress.Finish(false);
                    return;
                }

                ShouldProceedToPatchOptionWindow = Path != null && Storage != null;
                if (shouldAutoCloseWindow)
                {
                    Progress.Message("Initialized CS1 data, proceeding to patch options...", CurrentProgress, TotalProgress);
                }
                else
                {
                    Progress.Message("", CurrentProgress, TotalProgress);
                    if (ShouldProceedToPatchOptionWindow)
                    {
                        Progress.Error(
                            "Encountered problems while initializing CS1 data. "
                            + "Closing this window will proceed to the patch options anyway, but be aware that some patches may not work correctly. "
                            + "It is recommended to verify the game files using Steam or GOG Galaxy's build-in feature to do so, or to reinstall the game. "
                            + "Please also ensure you're trying to patch a compatible version of the game. (XSEED release version 1.6; other game versions are not compatible)"
                            );
                    }
                    else
                    {
                        Progress.Error(
                            "Unrecoverable issues while initializing CS1 data. "
                            + "Please ensure SenPatcher has read and write access to the selected game directory, then try again."
                            );
                    }
                }
                Progress.Finish(shouldAutoCloseWindow);
            }