public static void LoadDefaultUser() { try { string user = RegistryAccess.DefaultUsername; if (!ContainsUser(user)) { throw new KeyNotFoundException(); } string file = LocalDirectory.GetUserSubPath(user); string data = File.ReadAllText(file); DefaultUser = JsonConvert.DeserializeObject <UserInfo>(data); if (DefaultUser != null) { DefaultUser.Process(); } else { DefaultUser = new UserInfo(RegistryAccess.DefaultUsername); } } catch (Exception ex) { DefaultUser = new UserInfo(RegistryAccess.DefaultUsername); Logger.Add(ex.Message, "LocalDatabase|LoadDefaultUser()"); } }
public static bool UpdateAll() { const double PROBLEM_ALIVE_DAY = 1; const double USER_SUB_ALIVE_DAY = 0.5; bool result = true; //if database file is too old redownload string file = LocalDirectory.GetProblemInfoFile(); if (LocalDirectory.GetFileSize(file) < 100 || (new TimeSpan( DateTime.Now.Ticks - new FileInfo(file).LastWriteTime.Ticks ).TotalDays > PROBLEM_ALIVE_DAY)) { UVA_Arena.Internet.Downloader.DownloadProblemDatabase(); result = false; } //update user submissions if not available if (LocalDatabase.ContainsUser(RegistryAccess.DefaultUsername)) { file = LocalDirectory.GetUserSubPath(RegistryAccess.DefaultUsername); if (LocalDirectory.GetFileSize(file) < 50 || (new TimeSpan( DateTime.Now.Ticks - new FileInfo(file).LastWriteTime.Ticks ).TotalDays > USER_SUB_ALIVE_DAY)) { long sid = 0; if (LocalDatabase.DefaultUser != null) { sid = LocalDatabase.DefaultUser.LastSID; } UVA_Arena.Internet.Downloader.DownloadDefaultUserInfo(sid); } } //download category index if too old UVA_Arena.Internet.Downloader.DownloadCategoryIndex(); return(result); }
private void DelayInitialize(object background) { //run in background if ((bool)background) { this.Cursor = Cursors.AppStarting; System.Threading.ThreadPool.QueueUserWorkItem(DelayInitialize, false); return; } //load problem database LocalDatabase.RunLoadAsync(false); //load controls bool _initialized = false; this.BeginInvoke((MethodInvoker) delegate { //add controls AddControls(); //add buttons to the top right beside control buttons //AddActiveButtons(); _initialized = true; this.Cursor = Cursors.Default; Logger.Add("Initialized all controls", "Main Form"); loadingPanel.Visible = false; }); //update problem database if not available if (LocalDirectory.GetFileSize(LocalDirectory.GetProblemInfoFile()) < 100) { while (!_initialized) { System.Threading.Thread.Sleep(1000); } System.Threading.Thread.Sleep(2000); this.BeginInvoke((MethodInvoker) delegate { UVA_Arena.Internet.Downloader.DownloadProblemDatabase(); }); } //update user submissions if not available if (LocalDatabase.ContainsUser(RegistryAccess.DefaultUsername)) { string file = LocalDirectory.GetUserSubPath(RegistryAccess.DefaultUsername); if (LocalDirectory.GetFileSize(file) < 50) { System.Threading.Thread.Sleep(1000); this.BeginInvoke((MethodInvoker) delegate { Interactivity.userstat.DownloadUserSubs(RegistryAccess.DefaultUsername); }); } } //check for updates System.Threading.Thread.Sleep(10000); UpdateCheck.CheckForUpdate(); }