Ejemplo n.º 1
0
        private async void APILogonHandler(Common.APIData logonResponse, string apiKey, string host)
        {
            if (logonResponse.status == "success")
            {
                if (rememberMeBox.Checked)
                {
                    Settings.Default.savedApiKey = apiKey;
                    Settings.Default.savedHost   = Common.baseUrl;
                    Settings.Default.rememberMe  = true;
                    Settings.Default.Save();
                }

                Settings.Default.currentApiKey = apiKey;
                Settings.Default.currentUser   = logonResponse.response;

                BeginInvoke((Action) delegate
                {
                    gt.HideSync(loginBtn, true, Animation.Scale);
                    statusLabel.Text = $"Welcome aboard, {logonResponse.response}!";
                    statusLabel.Left = (Width - statusLabel.Width) / 2;
                    gt.ShowSync(statusLabel, false, Animation.Transparent);
                    Height = Height - 55;
                });

                await Task.Delay(1500);

                BeginInvoke((Action) delegate
                {
                    gt.HideSync(statusLabel, false, Animation.Transparent);
                    statusLabel.Text = "Enhancing your experience...";
                    statusLabel.Left = (Width - statusLabel.Width) / 2;
                    gt.ShowSync(statusLabel, false, Animation.Transparent);
                });

                await Task.Delay(1000);

                BeginInvoke((Action) delegate
                {
                    var ssMain = new StarSyncMain(logonResponse.response);
                    ssMain.Show();
                    Hide();
                });
            }

            else
            {
                BeginInvoke((Action) delegate
                {
                    gt.HideSync(genericLoading, false, Animation.Scale);
                    statusLabel.Text = "Login failed!";
                    statusLabel.Left = (Width - statusLabel.Width) / 2;
                    gt.ShowSync(statusLabel, false, Animation.Transparent);
                    loginBtn.Enabled = true;
                });
            }
        }
Ejemplo n.º 2
0
        private void RetrieveTask(Common.APIData responseObj)
        {
            CrossThreadedTextChange(statusLabel, "Downloading save package...");
            SyncConsoleLog(
                $@"Downloading save package from masterserver URL {Common.baseUrl}/saveData/{Settings.Default.currentUser}/{responseObj.response} as {Common.starSyncDataDir}\tempSavedata.zip");
            using (var webClient = new WebClient())
            {
                webClient.DownloadFile(
                    new Uri($"{Common.baseUrl}/saveData/{Settings.Default.currentUser}/{responseObj.response}"),
                    $@"{Common.starSyncDataDir}\tempSavedata.zip");
            }

            CrossThreadedTextChange(statusLabel, "Applying save package...");
            SyncConsoleLog(
                $@"Extracting save package {Common.starSyncDataDir}\tempSavedata.zip to {Common.stardewDataDir}...");
            using (var zip = ZipFile.Read($@"{Common.starSyncDataDir}\tempSavedata.zip"))
            {
                foreach (var entry in zip)
                {
                    entry.Extract(Common.stardewDataDir, ExtractExistingFileAction.OverwriteSilently);
                }
            }

            SyncConsoleLog(
                $@"Cleaning up temporary save package zip from {Common.starSyncDataDir}\tempSavedata.zip...");
            File.Delete($@"{Common.starSyncDataDir}\tempSavedata.zip");
            if (action == null)
            {
                CrossThreadedTextChange(statusLabel,
                                        "Sync Completed!<br><font style='font-size: 12;'>The new save has been applied.");
            }
            else
            {
                CrossThreadedTextChange(statusLabel,
                                        $"{actionKeyWord} Completed!<br><font style='font-size: 12;'>The new save file has been applied.");
            }
            SyncConsoleLog(@"Sync complete, the new save package has been applied.");
        }