public List <Release> GetAvailableUpdates()
        {
            string data = "";

            try
            {
                data = ApiHelper.GetData(StringStorage.Get("URL.APIRepository") + "/releases");
            }
            catch (Exception)
            {
                data = "[]";
            }

            List <Release> releases = JsonConvert.DeserializeObject <List <Release> >(data);

            Version currentVersion = new Version(AppVersion.Version);

            releases.RemoveAll(delegate(Release release)
            {
                string _v = release.Version;
                Version v = new Version(_v);
                bool res  = currentVersion >= v;
                return(res);
            });

            return(releases);
        }
Ejemplo n.º 2
0
        public async Task ProcessSetup()
        {
            string apiKey = await BrowserViewModel.Instance.SettingsGetApiKey();

            string username = await BrowserViewModel.Instance.SettingsGetUsername();

            bool processSettings = true;

            if (!ApiHelper.IsUserValid(apiKey, username))
            {
                BrowserViewModel.Instance.SendNotification(NotificationType.Danger, StringStorage.Get("Message.NoAPIorUsername"));
                processSettings = false;
            }

            if (processSettings)
            {
                SettingsManager.Instance.Settings["api"]["key"]  = apiKey;
                SettingsManager.Instance.Settings["api"]["user"] = username;
                SettingsManager.Instance.SettingsSave();
                BrowserViewModel.Instance.SendNotification(NotificationType.Success, StringStorage.Get("Message.SettingsSaved"));
                //StartupFinished?.Invoke(null, null);
                System.Diagnostics.Process.Start(FileManager.GetExecutablePath());
                Environment.Exit(0);
            }
        }
        private void OnUpdate()
        {
            if (!NetworkManager.Instance.HasConnection())
            {
                BrowserViewModel.Instance.SendNotification(NotificationType.Warning, StringStorage.Get("Message.NoInternet"));
                return;
            }

            //BrowserViewModel.Instance.SendNotification(NotificationType.Success, "Test: session iteration");
            OsuUser currentUserData = null;

            try
            {
                currentUserData = OsuApi.GetUser(CurrentSession.Username, (OsuMode)Enum.Parse(typeof(OsuMode), SettingsManager.Instance.Settings["api"]["gamemode"]));
            }
            catch (Exception)
            {
                BrowserViewModel.Instance.SendNotification(NotificationType.Danger, StringStorage.Get("Message.UserDataError"));
            }

            if (currentUserData != null)
            {
                if (CurrentSession.InitialData == null)
                {
                    CurrentSession.InitialData = SessionData.FromUser(currentUserData);
                }

                CurrentSession.CurrentData    = SessionData.FromUser(currentUserData);
                CurrentSession.DifferenceData = CurrentSession.CurrentData - CurrentSession.InitialData;

                BrowserViewModel.Instance.ApplySession(CurrentSession);
                BrowserViewModel.Instance.ApplyUser(currentUserData);

                int updateRate = Convert.ToInt32(SettingsManager.Instance.Settings["api"]["updateRate"]);
                if (updateRate != SessionThread.SleepTime)
                {
                    SessionThread.SleepTime = updateRate;
                }
            }

            lastIteration = DateTimeOffset.Now.ToUnixTimeSeconds();
            nextIteration = DateTimeOffset.Now.ToUnixTimeSeconds() + SessionThread.SleepTime;
        }
Ejemplo n.º 4
0
        private void Proceed()
        {
            //BrowserViewModel.Instance.AttachedBrowser.ExecuteScriptAsyncWhenPageLoaded("$(\"#tab_session_default_view\").show();");
            BrowserViewModel.Instance.AttachedBrowser.ExecuteScriptAsyncWhenPageLoaded("$(\"#tab_session_loader_view\").show();");
            Thread.Sleep(1000);
            BrowserViewModel.Instance.AttachedBrowser.ExecuteScriptAsyncWhenPageLoaded("appReady();");
            Thread.Sleep(100);
            PopulateSettings();


            BrowserViewModel.Instance.SetAppVersionText(AppVersion.Version);
            BrowserViewModel.Instance.SetChromiumVersionText("CEF: " + Cef.CefSharpVersion + ", Chromium: " + Cef.ChromiumVersion);

            if (!NetworkManager.Instance.HasConnection())
            {
                BrowserViewModel.Instance.SendNotification(NotificationType.Warning, StringStorage.Get("Message.NoInternet"));
            }
            SessionManager.Instance.PrepareSession();
            UpdateManager.Instance.Start();
            //ToolLocalApi.Instance.Start();
        }
Ejemplo n.º 5
0
        public void CheckSetup()
        {
            bool exists         = SettingsManager.Instance.LoadOrCreateSettings();
            bool validApiOrUser = ApiHelper.IsKeyValid(SettingsManager.Instance.Settings["api"]["key"]) &&
                                  ApiHelper.IsUserValid(SettingsManager.Instance.Settings["api"]["key"], SettingsManager.Instance.Settings["api"]["user"]);

            if (!exists || !validApiOrUser)
            {
                if (exists && !validApiOrUser)
                {
                    BrowserViewModel.Instance.SendNotification(NotificationType.Danger, StringStorage.Get("Message.NoAPIorUsername"));
                }

                BrowserViewModel.Instance.AttachedJavascriptWrapper.Modal.Show("#generateSettingsModal");
                cefOsuApp.SetupFinished += (object sender, EventArgs e) =>
                {
                    cefOsuApp.GetWindow().Dispatcher.Invoke(() =>
                    {
                        Task.Run(async() =>
                        {
                            BrowserViewModel.Instance.AttachedJavascriptWrapper.SetElementDisabled("#settingsConfirmButton", true);
                            BrowserViewModel.Instance.AttachedJavascriptWrapper.SetHtml("#settingsConfirmButton", "<span class=\"spinner-border spinner-border-sm\" role=\"status\" aria-hidden=\"true\"></span> saving");

                            Task task = ProcessSetup();
                            if (await Task.WhenAny(task, Task.Delay(5000)) != task)
                            {
                                BrowserViewModel.Instance.SendNotification(NotificationType.Danger, StringStorage.Get("Message.SomethingWrong"));
                            }

                            //MessageBox.Show(apiKey);
                            BrowserViewModel.Instance.AttachedJavascriptWrapper.SetElementDisabled("#settingsConfirmButton", false);
                            BrowserViewModel.Instance.AttachedJavascriptWrapper.SetHtml("#settingsConfirmButton", "Save");
                        });
                    });
                };
            }
            else
            {
                StartupFinished?.Invoke(null, null);
            }
        }
        public void PrepareUpdate(Release update)
        {
            BrowserViewModel.Instance.AttachedJavascriptWrapper.Show("#cardUpdateReady");
            BrowserViewModel.Instance.AttachedJavascriptWrapper.SetHtml("#updatemanagerVersionID", update.Version);

            BrowserViewModel.Instance.AttachedJavascriptWrapper.Show("#navigationUpdateWarning");
            BrowserViewModel.Instance.AttachedJavascriptWrapper.SetHtml("#updatemanagerVersionBody", StringStorage.Get("Text.NoUpdate"));
            Markdown md           = new Markdown();
            string   updateString = "<div style=\"-webkit-text-size-adjust: 50%;\">";

            updateString += md.Transform(update.Body);
            updateString += "</div>";
            BrowserViewModel.Instance.AttachedJavascriptWrapper.SetHtml("#updatemanagerVersionBody", HttpUtility.JavaScriptStringEncode(updateString));
        }
Ejemplo n.º 7
0
        private async void PopulateTabData()
        {
            string             tabsDataTask = "getTabFields();";
            JavascriptResponse result_data  = null;

            int jsAttempts = 0;

            do
            {
                try
                {
                    jsAttempts++;
                    JavascriptResponse res = await BrowserViewModel.Instance.AttachedBrowser.EvaluateScriptAsync(tabsDataTask);

                    result_data = res;
                    if (res != null && res.Result != null)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    if (jsAttempts == 5)
                    {
                        throw e;
                    }

                    await Task.Delay(1000);
                }
            } while (true);
            List <object> data = (List <object>)result_data.Result;

            data.ForEach(element =>
            {
                string name = (string)element;
                string path = "wwwroot/tabs/tab_" + name + ".html";
                if (File.Exists(path))
                {
                    string file_data     = FileManager.ReadAllText(path);
                    string prepared_file = HttpUtility.JavaScriptStringEncode(file_data);
                    BrowserViewModel.Instance.AttachedBrowser.ExecuteScriptAsyncWhenPageLoaded("populateTab('" + name + "','" + prepared_file + "');");
                }
                else
                {
                    BrowserViewModel.Instance.SendNotification(NotificationType.Danger, String.Format(StringStorage.Get("Message.MissingTabContent"), name));
                }
            });
            Thread.Sleep(1000);
            PopulateAddons();
        }
        public SessionManager()
        {
            SessionFiles = new List <SessionFileData>();
            if (File.Exists("Data/stored_sessions.json"))
            {
                string data = string.Empty;
                try
                {
                    data = File.ReadAllText("Data/stored_sessions.json");
                }
                catch (Exception)
                {
                    BrowserViewModel.Instance.SendNotification(NotificationType.Warning, StringStorage.Get("Message.UnreadableSession"));
                }

                if (!string.IsNullOrEmpty(data))
                {
                    List <SessionFileData> storedSessions = null;
                    try
                    {
                        storedSessions = JsonConvert.DeserializeObject <List <SessionFileData> >(data);
                    }
                    catch (Exception)
                    {
                        BrowserViewModel.Instance.SendNotification(NotificationType.Warning, StringStorage.Get("Message.UnreadableSession"));
                    }
                    if (storedSessions != null || storedSessions.Count > 0)
                    {
                        SessionFiles.AddRange(storedSessions);
                        PopulateLoadList();
                    }
                }
            }
        }
        //Prepare a new session
        public void PrepareSession(Session session = null)
        {
            SessionThread?.Join();

            if (session == null)
            {
                CurrentSession = new Session
                {
                    Username = SettingsManager.Instance.Settings["api"]["user"]
                };
            }
            else
            {
                CurrentSession = session;
            }

            if (CurrentSession.ReadOnly)
            {
                OsuUser currentUserData = null;
                try
                {
                    currentUserData = OsuApi.GetUser(CurrentSession.Username, (OsuMode)Enum.Parse(typeof(OsuMode), SettingsManager.Instance.Settings["api"]["gamemode"]));
                }
                catch (Exception)
                {
                    BrowserViewModel.Instance.SendNotification(NotificationType.Danger, StringStorage.Get("Message.UserDataError"));
                    return;
                }
                BrowserViewModel.Instance.ApplySession(CurrentSession);
                BrowserViewModel.Instance.ApplyUser(currentUserData);

                StopProgressHandler();
                BrowserViewModel.Instance.AttachedJavascriptWrapper.Hide("#sessionProgressTime");
                BrowserViewModel.Instance.AttachedJavascriptWrapper.Show("#sessionProgressReadonly");

                string startDate = DateTimeOffset.FromUnixTimeSeconds(CurrentSession.SessionDate).ToString("MMMM dd yyyy HH:mm:ss");
                string endDate   = DateTimeOffset.FromUnixTimeSeconds(CurrentSession.SessionEndDate).ToString("MMMM dd yyyy HH:mm:ss");

                BrowserViewModel.Instance.AttachedJavascriptWrapper.SetHtml("#sessionProgressReadonlyText", startDate + " to " + endDate);
            }
            else
            {
                SessionThread = new ExtendedThread(() => OnUpdate(), Convert.ToInt32(SettingsManager.Instance.Settings["api"]["updateRate"]));

                lastIteration = DateTimeOffset.Now.ToUnixTimeSeconds();
                nextIteration = DateTimeOffset.Now.ToUnixTimeSeconds() + SessionThread.SleepTime;

                StartProgressHandler();
                SessionThread.Start();

                BrowserViewModel.Instance.AttachedJavascriptWrapper.Hide("#sessionProgressReadonly");

                if (SettingsManager.Instance.Settings["display"]["showTimer"] == "true")
                {
                    BrowserViewModel.Instance.AttachedJavascriptWrapper.Show("#sessionProgressTime");
                }
            }
        }