コード例 #1
0
        public EditorForm()
        {
            var path = !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath)
                ? Program.UserConfig.GameFilesPath
                : GameScannnerApi.GetGameFilesRootPath();

            try
            {
                _gameScannner = GameScannnerApi.InstallGameEditor(Program.UserConfig.IsSteamVersion,
                                                                  path);
            }
            catch (Exception)
            {
                //
            }
            InitializeComponent();

            SkinHelperFonts.SetFont(Controls);

            if (_gameScannner != null && DownloadFileUtils.IsConnectedToInternet())
            {
                if (_gameScannner.QuickScan().GetAwaiter().GetResult())
                {
                    Btn_Install_Editor.Enabled = false;
                    btn_Browse.Enabled         = true;

                    label2.Text      = @"Installed";
                    label2.ForeColor = Color.Green;
                    _isAutoRun       = true;
                }
                else
                {
                    label2.Text      = @"Non-Installed Or Outdated";
                    label2.ForeColor = Color.Red;

                    Btn_Install_Editor.Enabled = true;
                    btn_Browse.Enabled         = false;
                }
            }
            else
            {
                Btn_Install_Editor.Enabled = true;
                btn_Browse.Enabled         = true;

                label2.Text      = @"Unknow";
                label2.ForeColor = Color.OrangeRed;
            }
        }
コード例 #2
0
        private async Task DoDownloadAndInstallProcdump(CancellationToken ct = new CancellationToken())
        {
            const string downloadLink = @"https://download.sysinternals.com/files/Procdump.zip";

            var tempFileName = Path.GetTempFileName();

            try
            {
                var dowloadProgress = new Progress <DownloadFileProgress>();
                dowloadProgress.ProgressChanged += (o, ea) =>
                {
                    progressBar1.Value = Convert.ToInt32(Math.Floor(75 * ((double)ea.ProgressPercentage / 100)));
                };
                var downloadFileAsync = new DownloadFileUtils(new Uri(downloadLink), tempFileName, dowloadProgress);
                await downloadFileAsync.DoDownload(ct);

                var extractProgress = new Progress <ZipFileProgress>();
                extractProgress.ProgressChanged += (o, ea) =>
                {
                    progressBar1.Value =
                        75 + Convert.ToInt32(Math.Floor(25 * ((double)ea.ProgressPercentage / 100)));
                };
                await ZipUtils.DoExtractZipFile(tempFileName, AppDomain.CurrentDomain.BaseDirectory, extractProgress,
                                                ct);
            }
            finally
            {
                if (File.Exists(tempFileName))
                {
                    File.Delete(tempFileName);
                }
            }
            //
            DialogResult = DialogResult.OK;
            Close();
        }
コード例 #3
0
        private static async Task <bool> ScanAndRepairFile(GameFileInfo fileInfo, string gameFilePath,
                                                           IProgress <ScanAndRepairFileProgress> progress,
                                                           CancellationToken ct)
        {
            try
            {
                var filePath = Path.Combine(gameFilePath, fileInfo.FileName);

                ct.ThrowIfCancellationRequested();
                //#1 File Check
                progress?.Report(new ScanAndRepairFileProgress(fileInfo.FileName, 1,
                                                               new ExLog(LogLevel.Info, "-------------------------\r\n" +
                                                                         $"[{fileInfo.FileName}]\r\n" +
                                                                         "-------------------------\r\n" +
                                                                         "      - Checking file...")));

                if (RunFileCheck(filePath, fileInfo.Size, fileInfo.Crc32))
                {
                    goto end;
                }

                progress?.Report(new ScanAndRepairFileProgress(fileInfo.FileName, 5,
                                                               new ExLog(LogLevel.Warn, "          Warning: File is missing or invalid.")));

                ct.ThrowIfCancellationRequested();
                //#6 Download File
                progress?.Report(new ScanAndRepairFileProgress(fileInfo.FileName, 6,
                                                               new ExLog(LogLevel.Info, "      - File downloading...")));

                var dowloadProgress = new Progress <DownloadFileProgress>();
                if (progress != null)
                {
                    dowloadProgress.ProgressChanged += (o, ea) =>
                    {
                        progress.Report(new ScanAndRepairFileProgress(fileInfo.FileName,
                                                                      6 + Convert.ToInt32(Math.Floor((double)ea.ProgressPercentage / 100 * (65 - 6))), ea));
                    }
                }
                ;
                var tempFileName = Path.Combine(GetTempPath(), Path.GetRandomFileName());
                var x            = new DownloadFileUtils(new Uri(fileInfo.HttpLink), tempFileName, dowloadProgress);
                await x.DoDownload(ct);

                ct.ThrowIfCancellationRequested();
                //#65 Check Downloaded File
                progress?.Report(new ScanAndRepairFileProgress(fileInfo.FileName, 65,
                                                               new ExLog(LogLevel.Info, "      - Checking downloaded file...")));

                if (!RunFileCheck(tempFileName, fileInfo.BinSize, fileInfo.BinCrc32))
                {
                    if (File.Exists(tempFileName))
                    {
                        File.Delete(tempFileName);
                    }

                    throw new Exception("Downloaded file is invalid!");
                }

                ct.ThrowIfCancellationRequested();
                //#70 Extract downloaded file
                var tmpFilePath   = tempFileName;
                var tempFileName2 = Path.Combine(GetTempPath(), Path.GetRandomFileName());
                if (ZipUtils.IsL33TZipFile(tempFileName))
                {
                    ct.ThrowIfCancellationRequested();
                    //
                    progress?.Report(new ScanAndRepairFileProgress(fileInfo.FileName, 70,
                                                                   new ExLog(LogLevel.Info, "      - Extract downloaded file...")));

                    var extractProgress = new Progress <ZipFileProgress>();
                    if (progress != null)
                    {
                        extractProgress.ProgressChanged += (o, ea) =>
                        {
                            progress.Report(new ScanAndRepairFileProgress(fileInfo.FileName,
                                                                          70 + Convert.ToInt32(Math.Floor((double)ea.ProgressPercentage / 100 * (90 - 70))),
                                                                          ea));
                        }
                    }
                    ;
                    await ZipUtils.DoExtractL33TZipFile(tempFileName, tempFileName2, extractProgress, ct);

                    ct.ThrowIfCancellationRequested();
                    //#90 Check Downloaded File
                    if (!RunFileCheck(tempFileName2, fileInfo.Size, fileInfo.Crc32))
                    {
                        if (File.Exists(tempFileName))
                        {
                            File.Delete(tempFileName);
                        }

                        if (File.Exists(tempFileName2))
                        {
                            File.Delete(tempFileName2);
                        }

                        throw new Exception("Extracted file is invalid!");
                    }

                    tmpFilePath = tempFileName2;
                }
                else if (ZipUtils.IsL66TZipFile(tempFileName))
                {
                    ct.ThrowIfCancellationRequested();
                    //
                    progress?.Report(new ScanAndRepairFileProgress(fileInfo.FileName, 70,
                                                                   new ExLog(LogLevel.Info, "      - Extract downloaded file...")));

                    var extractProgress = new Progress <ZipFileProgress>();
                    if (progress != null)
                    {
                        extractProgress.ProgressChanged += (o, ea) =>
                        {
                            progress.Report(new ScanAndRepairFileProgress(fileInfo.FileName,
                                                                          70 + Convert.ToInt32(Math.Floor((double)ea.ProgressPercentage / 100 * (90 - 70))),
                                                                          ea));
                        }
                    }
                    ;
                    await ZipUtils.DoExtractL66TZipFile(tempFileName, tempFileName2, extractProgress, ct);

                    ct.ThrowIfCancellationRequested();
                    //#90 Check Downloaded File
                    if (!RunFileCheck(tempFileName2, fileInfo.Size, fileInfo.Crc32))
                    {
                        if (File.Exists(tempFileName))
                        {
                            File.Delete(tempFileName);
                        }

                        if (File.Exists(tempFileName2))
                        {
                            File.Delete(tempFileName2);
                        }

                        throw new Exception("Extracted file is invalid!");
                    }

                    tmpFilePath = tempFileName2;
                }

                ct.ThrowIfCancellationRequested();
                //#95 Move new file to game folder
                progress?.Report(new ScanAndRepairFileProgress(fileInfo.FileName, 95,
                                                               new ExLog(LogLevel.Info, "      - Moving new file...")));

                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                var pathName = Path.GetDirectoryName(filePath);
                if (!string.IsNullOrEmpty(pathName) && !Directory.Exists(pathName))
                {
                    Directory.CreateDirectory(pathName);
                }

                File.Move(tmpFilePath, filePath);

                //#99 Removing temporary file
                progress?.Report(new ScanAndRepairFileProgress(fileInfo.FileName, 99,
                                                               new ExLog(LogLevel.Info, "      - Clean-up temporary files...")));

                if (File.Exists(tmpFilePath))
                {
                    File.Delete(tmpFilePath);
                }

                if (File.Exists(tempFileName))
                {
                    File.Delete(tempFileName);
                }

                if (File.Exists(tempFileName2))
                {
                    File.Delete(tempFileName2);
                }

end:
                //#100
                progress?.Report(new ScanAndRepairFileProgress(fileInfo.FileName, 100));
            }
            catch (AggregateException e)
            {
                progress?.Report(new ScanAndRepairFileProgress(fileInfo.FileName, 100,
                                                               new ExLog(LogLevel.Info, "-------------------------\r\n" +
                                                                         "!!! Error !!!\r\n" +
                                                                         "-------------------------\r\n" +
                                                                         $"{e.Message}")));

                return(false);
            }
            return(true);
        }
コード例 #4
0
        public static async void StartGame(bool isOffline = false)
        {
            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length > 0)
            {
                MsgBox.ShowMessage(@"Game already running!");
                return;
            }

            //QuickGameScan
            if (!isOffline || DownloadFileUtils.IsConnectedToInternet())
            {
                try
                {
                    var gameFilePath = !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath)
                        ? Program.UserConfig.GameFilesPath
                        : GameScannnerApi.GetGameFilesRootPath();

                    var gameScannner = new GameScannnerApi(gameFilePath, Program.UserConfig.IsSteamVersion);

retry:
                    if (!await gameScannner.QuickScan())
                    {
                        bool success;
                        using (var form =
                                   new MsgBoxYesNo(
                                       @"Error: Your game files are corrupted or outdated. Click ""Yes"" to run a ""Game Scan"" to fix your game files, or ""No"" to ignore the error (not recommended).")
                               )
                        {
                            var dr = form.ShowDialog();
                            if (dr == DialogResult.OK)
                            {
                                using (var form2 = new GameScan())
                                {
                                    form2.ShowDialog();
                                    success = false;
                                }
                            }
                            else
                            {
                                success = true;
                            }
                        }
                        if (!success)
                        {
                            goto retry;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MsgBox.ShowMessage(
                        $"Warning: Error during quick scan. Error message: {ex.Message}",
                        @"Celeste Fan Project",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            //isSteam
            if (!Program.UserConfig.IsSteamVersion)
            {
                var steamApiDll = Path.Combine(Program.UserConfig.GameFilesPath, "steam_api.dll");
                if (File.Exists(steamApiDll))
                {
                    File.Delete(steamApiDll);
                }
            }

            //MpSettings
            if (!isOffline && Program.UserConfig.MpSettings != null)
            {
                if (Program.UserConfig.MpSettings.ConnectionType == ConnectionType.Wan)
                {
                    Program.UserConfig.MpSettings.PublicIp = Program.CurrentUser.Ip;

                    if (Program.UserConfig.MpSettings.PortMappingType == PortMappingType.Upnp)
                    {
                        try
                        {
                            await OpenNat.MapPortTask(1000, 1000);
                        }
                        catch (Exception)
                        {
                            Program.UserConfig.MpSettings.PortMappingType = PortMappingType.NatPunch;

                            MsgBox.ShowMessage(
                                "Error: Upnp device not found! \"UPnP Port Mapping\" has been disabled.",
                                @"Celeste Fan Project",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
コード例 #5
0
        private async void MainForm_Load(object sender, EventArgs e)
        {
            //CleanUpFiles
            try
            {
                Misc.CleanUpFiles(Directory.GetCurrentDirectory(), "*.old");
            }
            catch (Exception ex)
            {
                MsgBox.ShowMessage(
                    $"Warning: Error during files clean-up. Error message: {ex.Message}",
                    @"Celeste Fan Project",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (!DownloadFileUtils.IsConnectedToInternet())
            {
                return;
            }

            //Update Check
            try
            {
                if (await UpdaterForm.GetGitHubVersion() > Assembly.GetExecutingAssembly().GetName().Version)
                {
                    using (var form =
                               new MsgBoxYesNo(
                                   @"An update is avalaible. Click ""Yes"" to install it, or ""No"" to ignore it (not recommended).")
                           )
                    {
                        var dr = form.ShowDialog();
                        if (dr == DialogResult.OK)
                        {
                            using (var form2 = new UpdaterForm())
                            {
                                form2.ShowDialog();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowMessage(
                    $"Warning: Error during update check. Error message: {ex.Message}",
                    @"Celeste Fan Project",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            //Auto Login
            if (Program.UserConfig?.LoginInfo == null)
            {
                return;
            }

            if (!Program.UserConfig.LoginInfo.AutoLogin)
            {
                return;
            }

            panelManager1.Enabled = false;
            try
            {
                var response = await Program.WebSocketApi.DoLogin(Program.UserConfig.LoginInfo.Email,
                                                                  Program.UserConfig.LoginInfo.Password);

                if (response.Result)
                {
                    Program.CurrentUser = response.User;

                    gamerCard1.UserName = Program.CurrentUser.ProfileName;
                    gamerCard1.Rank     = $@"{Program.CurrentUser.Rank}";

                    panelManager1.SelectedPanel = managedPanel1;
                }
            }
            catch (Exception)
            {
                //
            }
            panelManager1.Enabled = true;
        }
コード例 #6
0
        private static async Task DoDownloadAndInstallUpdate(bool isSteam, IProgress <int> progress,
                                                             CancellationToken ct)
        {
            Misc.CleanUpFiles(Directory.GetCurrentDirectory(), "*.old");

            var gitVersion = await GetGitHubVersion().ConfigureAwait(false);

            progress.Report(3);

            if (gitVersion <= Assembly.GetExecutingAssembly().GetName().Version)
            {
                return;
            }

            ct.ThrowIfCancellationRequested();

            const string zipName      = "Celeste_Launcher.zip";
            var          downloadLink = $"{ReleaseZipUrl}{gitVersion}/{zipName}";

            //Download File
            progress.Report(5);

            var dowloadProgress = new Progress <DownloadFileProgress>();

            dowloadProgress.ProgressChanged += (o, ea) =>
            {
                progress.Report(5 + Convert.ToInt32(Math.Floor((65 - 5) * ((double)ea.ProgressPercentage / 100))));
            };

            var tempFileName = Path.GetTempFileName();

            var downloadFileAsync = new DownloadFileUtils(new Uri(downloadLink), tempFileName, dowloadProgress);

            try
            {
                await downloadFileAsync.DoDownload(ct);
            }
            catch (AggregateException)
            {
                if (File.Exists(tempFileName))
                {
                    File.Delete(tempFileName);
                }

                throw;
            }

            //Extract File
            progress.Report(65);

            var extractProgress = new Progress <ZipFileProgress>();

            extractProgress.ProgressChanged += (o, ea) =>
            {
                progress.Report(
                    65 + Convert.ToInt32(Math.Floor((90 - 65) * ((double)ea.ProgressPercentage / 100))));
            };
            var tempDir = Path.Combine(Path.GetTempPath(), $"Celeste_Launcher_v{gitVersion}");

            if (Directory.Exists(tempDir))
            {
                Misc.CleanUpFiles(tempDir, "*.*");
            }

            try
            {
                await ZipUtils.DoExtractZipFile(tempFileName, tempDir, extractProgress, ct);
            }
            catch (AggregateException)
            {
                Misc.CleanUpFiles(tempDir, "*.*");
                throw;
            }
            finally
            {
                if (File.Exists(tempFileName))
                {
                    File.Delete(tempFileName);
                }
            }

            //Move File
            progress.Report(90);

            var destinationDir = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar;

            try
            {
                Misc.MoveFiles(tempDir, destinationDir);
            }
            finally
            {
                Misc.CleanUpFiles(tempDir, "*.*");
            }

            //isSteam Version
            if (isSteam)
            {
                progress.Report(95);
                Steam.ConvertToSteam(destinationDir);
            }

            //Clean Old File
            progress.Report(97);
            Misc.CleanUpFiles(Directory.GetCurrentDirectory(), "*.old");

            //
            progress.Report(100);
        }