public bool SaveDownload(IStatusProvider statusProvider) { Exception exception; try { if (!base.ContentType.CurrentUserCanDownload) { return false; } string downloadPath = this.GetDownloadPath(); string path = string.Format(@"{0}\content.partial", downloadPath); if (!File.Exists(path)) { ErrorLog.WriteLine("The expected download file: {0} was not found.", new object[] { path }); if (statusProvider != null) { statusProvider.SetStatus("<LOC>An error occurred while downloading file, please try again.", 0xbb8, new object[0]); } return false; } statusProvider.SetStatus("<LOC>Extracting File(s)...", new object[0]); Compression.Unzip(path); File.Delete(path); try { this.Run(); } catch (Exception exception1) { exception = exception1; ErrorLog.WriteLine(exception); } return true; } catch (Exception exception2) { exception = exception2; ErrorLog.WriteLine(exception); return false; } }
public bool SaveDownload(IStatusProvider statusProvider) { if (!base.ContentType.CurrentUserCanDownload) { if (statusProvider != null) { statusProvider.SetStatus("<LOC>You do not have permission to download this content", new object[0]); } return false; } try { string downloadPath = this.GetDownloadPath(); string path = downloadPath + @"\content.partial"; bool flag = false; foreach (string str3 in Directory.GetDirectories(this.GetDownloadPath(true))) { if (!(str3 == downloadPath)) { flag = true; Directory.Delete(str3, true); } } foreach (string str4 in Directory.GetFiles(this.GetDownloadPath(true), "*.*", SearchOption.TopDirectoryOnly)) { flag = true; System.IO.File.Delete(str4); } if (flag) { AdditionalContent.DeleteMyContent(this, true, false, true); foreach (IAdditionalContent content in AdditionalContent.MyContent.ToArray()) { if (((content.TypeID == base.TypeID) && (content.Name == base.Name)) && (content.Version != base.Version)) { AdditionalContent.MyContent.Remove(content); } } } if (!System.IO.File.Exists(path)) { ErrorLog.WriteLine("The expected download file: {0} was not found.", new object[] { path }); if (statusProvider != null) { statusProvider.SetStatus("<LOC>An error occurred while downloading file, please try again.", 0xbb8, new object[0]); } return false; } statusProvider.SetStatus("<LOC>Extracting File(s)...", new object[0]); Compression.Unzip(path, this.GetDownloadPath(true)); if (!Directory.Exists(this.GetDownloadPath())) { Directory.CreateDirectory(this.GetDownloadPath()); } System.IO.File.WriteAllText(Path.Combine(this.GetDownloadPath(), string.Format("{0}.version", this.ModName)), "Do not delete this file, it is required to maintain this mod's version"); Thread.Sleep(50); DateTime now = DateTime.Now; while (System.IO.File.Exists(path)) { try { System.IO.File.Delete(path); } catch { if ((DateTime.Now - now) > TimeSpan.FromSeconds(3.0)) { break; } Thread.Sleep(50); } } return true; } catch (Exception exception) { ErrorLog.WriteLine(exception); return false; } }
public static void ReCalculateAllAwards(IStatusProvider statusProvider) { DateTime now = DateTime.Now; StringBuilder sql = new StringBuilder(100); string str = "temp_player_awards"; string str2 = "old_player_awards"; Avatar.ClearCachedData(); AwardCategory.ClearCachedData(); AwardSet.ClearCachedData(); GPG.Multiplayer.Statistics.Award.ClearCachedData(); try { if (statusProvider != null) { statusProvider.SetStatus("Clearing old temp data if it exists", new object[0]); } Thread.Sleep(500); sql.AppendFormat("DROP TABLE IF EXISTS temp_player_ids;", new object[0]); sql.AppendFormat("DROP TABLE IF EXISTS {0};", str2); sql.AppendFormat("DROP TABLE IF EXISTS {0};", str); sql.AppendFormat("DROP TABLE IF EXISTS old_player_avatar;", new object[0]); sql.AppendFormat("DROP TABLE IF EXISTS temp_player_avatar;", new object[0]); sql.AppendFormat("DROP TABLE IF EXISTS temp_tournament_results;", new object[0]); sql.AppendFormat("CREATE TABLE temp_player_ids (", new object[0]); sql.AppendFormat("player_id INTEGER UNSIGNED NOT NULL,", new object[0]); sql.AppendFormat("PRIMARY KEY(player_id)", new object[0]); sql.AppendFormat(") SELECT principal AS player_id FROM principal_info;", new object[0]); ExecuteQuery(sql); sql.AppendFormat("UPDATE tournaments SET round = (SELECT max(wins + losses + draws) FROM tournament_round WHERE tournament_round.tournament_id = tournaments.tournament_id) WHERE (SELECT max(wins + losses + draws) FROM tournament_round WHERE tournament_round.tournament_id = tournaments.tournament_id) is not null", new object[0]); ExecuteQuery(sql); sql.AppendFormat("CREATE TABLE temp_tournament_results ", new object[0]); sql.AppendFormat("SELECT tournaments.tournament_id, new.principal_id, ", new object[0]); sql.AppendFormat("(SELECT count(*) FROM tournament_round old WHERE old.tournament_id = tournaments.tournament_id AND ", new object[0]); sql.AppendFormat("old.round = tournaments.round AND ", new object[0]); sql.AppendFormat("( (old.wins + (0.5 * old.draws)) > (new.wins + (0.5 * new.draws)) OR ", new object[0]); sql.AppendFormat("( (old.wins + (0.5 * old.draws)) = (new.wins + (0.5 * new.draws)) AND (old.seed < new.seed) ) ) ) + 1 as finish_pos ", new object[0]); sql.AppendFormat("FROM tournaments, tournament_round new ", new object[0]); sql.AppendFormat("WHERE ", new object[0]); sql.AppendFormat("tournaments.tournament_id = new.tournament_id ", new object[0]); sql.AppendFormat("AND ", new object[0]); sql.AppendFormat("tournaments.round = new.round ", new object[0]); sql.AppendFormat("ORDER BY tournaments.tournament_id DESC, (wins + (0.5 * draws)) DESC, seed ASC;", new object[0]); sql.AppendFormat("ALTER TABLE temp_tournament_results ADD index temp_tournament_results_ix1 (principal_id, finish_pos);", new object[0]); ExecuteQuery(sql); if (statusProvider != null) { statusProvider.SetStatus("Creating temp schema for avatars", new object[0]); } Thread.Sleep(500); sql.AppendFormat("CREATE TABLE temp_player_avatar (", new object[0]); sql.AppendFormat("player_avatar_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,", new object[0]); sql.AppendFormat("player_id INTEGER UNSIGNED NULL,", new object[0]); sql.AppendFormat("avatar_id INTEGER UNSIGNED NULL,", new object[0]); sql.AppendFormat("manual_assignment BOOL NULL DEFAULT 0,", new object[0]); sql.AppendFormat("PRIMARY KEY(player_avatar_id),", new object[0]); sql.AppendFormat("UNIQUE INDEX temp_player_avatar_index3199(player_id, avatar_id),", new object[0]); sql.AppendFormat("INDEX temp_player_avatar_index3203(avatar_id),", new object[0]); sql.AppendFormat("INDEX temp_player_avatar_index3208(manual_assignment)", new object[0]); sql.AppendFormat(");", new object[0]); ExecuteQuery(sql); foreach (Avatar avatar in Avatar.AllAvatars.Values) { if (((avatar.AchievementQuery != null) && (avatar.AchievementQuery.Length >= 1)) && (avatar.AchievementQuery != "(null)")) { DateTime time2 = DateTime.Now; if (statusProvider != null) { statusProvider.SetStatus("Calculating achievement status for avatar: {0}", new object[] { avatar.Description }); } sql.AppendFormat("INSERT INTO temp_player_avatar (player_id, avatar_id, manual_assignment) (SELECT player_id, {0}, 0 FROM temp_player_ids WHERE ({1}) > 0);", avatar.ID, avatar.AchievementQuery); ExecuteQuery(sql); TimeSpan span = (TimeSpan) (DateTime.Now - time2); if (statusProvider != null) { statusProvider.SetStatus("Finished calculating avatar: {0} in {1} seconds", new object[] { avatar.Description, span.TotalSeconds }); } Thread.Sleep(500); } } if (statusProvider != null) { statusProvider.SetStatus("Fetching manual assigments for avatars.", new object[0]); } sql.AppendFormat("REPLACE INTO temp_player_avatar (player_id, avatar_id, manual_assignment) ", new object[0]); sql.AppendFormat("SELECT player_id, avatar_id, manual_assignment FROM player_avatar WHERE manual_assignment = 1", new object[0]); ExecuteQuery(sql); if (statusProvider != null) { statusProvider.SetStatus("Clearing player_avatars where the avatar no longer exists for the player.", new object[0]); } sql.AppendFormat("UPDATE player_display_awards ", new object[0]); sql.AppendFormat("LEFT OUTER JOIN temp_player_avatar ON ", new object[0]); sql.AppendFormat(" player_display_awards.avatar = temp_player_avatar.avatar_id AND player_display_awards.player_id = temp_player_avatar.player_id ", new object[0]); sql.AppendFormat("SET player_display_awards.avatar = temp_player_avatar.avatar_id ", new object[0]); ExecuteQuery(sql); if (statusProvider != null) { statusProvider.SetStatus("Moving temp avatar data to live data", new object[0]); } Thread.Sleep(0x3e8); sql.AppendFormat("RENAME TABLE player_avatar TO old_player_avatar, temp_player_avatar TO player_avatar;", new object[0]); ExecuteQuery(sql); if (statusProvider != null) { statusProvider.SetStatus("Creating temp schema for awards", new object[0]); } sql.AppendFormat("CREATE TABLE {0} (", str); sql.AppendFormat("player_award_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,", new object[0]); sql.AppendFormat("player_id INTEGER UNSIGNED NULL,", new object[0]); sql.AppendFormat("award_id INTEGER UNSIGNED NULL,", new object[0]); sql.AppendFormat("progress INTEGER UNSIGNED NULL DEFAULT 0,", new object[0]); sql.AppendFormat("is_achieved BOOL NULL DEFAULT 0,", new object[0]); sql.AppendFormat("show_progress BOOL NULL DEFAULT 0,", new object[0]); sql.AppendFormat("PRIMARY KEY(player_award_id),", new object[0]); sql.AppendFormat("INDEX temp_player_award_status_index3095(player_id),", new object[0]); sql.AppendFormat("INDEX temp_player_award_status_index3101(is_achieved),", new object[0]); sql.AppendFormat("INDEX temp_player_award_status_index3102(show_progress),", new object[0]); sql.AppendFormat("UNIQUE INDEX temp_player_award_index3141(player_id, award_id)", new object[0]); sql.AppendFormat(");", new object[0]); ExecuteQuery(sql); if (statusProvider != null) { statusProvider.SetStatus("Creating temp units agg table", new object[0]); } sql.AppendFormat("DROP TABLE IF EXISTS temp_player_units;", new object[0]); sql.AppendFormat("CREATE TABLE temp_player_units (", new object[0]); sql.AppendFormat("principal_id INT NOT NULL,", new object[0]); sql.AppendFormat("amount INT NOT NULL,", new object[0]); sql.AppendFormat("category VARCHAR(10) NOT NULL,", new object[0]); sql.AppendFormat("PRIMARY KEY(category, principal_id),", new object[0]); sql.AppendFormat("INDEX temp_player_units_ix1(category, amount, principal_id)", new object[0]); sql.AppendFormat(");", new object[0]); ExecuteQuery(sql); sql.AppendFormat("INSERT INTO temp_player_units (category, principal_id, amount) ", new object[0]); sql.AppendFormat("(SELECT 'aeonexp', principal_id, SUM(built) FROM player_units WHERE unit_id in ('UAL0401', 'UAS0401', 'UAA0310') GROUP BY principal_id);", new object[0]); ExecuteQuery(sql); sql.AppendFormat("INSERT INTO temp_player_units (category, principal_id, amount) ", new object[0]); sql.AppendFormat("(SELECT 'cybranexp', principal_id, SUM(built) FROM player_units WHERE unit_id in ('URA0401', 'URL0401', 'URL0402') GROUP BY principal_id);", new object[0]); ExecuteQuery(sql); sql.AppendFormat("INSERT INTO temp_player_units (category, principal_id, amount) ", new object[0]); sql.AppendFormat("(SELECT 'uefexp', principal_id, SUM(built) FROM player_units WHERE unit_id in ('UEB2401', 'UEL0401', 'UES0401') GROUP BY principal_id);", new object[0]); ExecuteQuery(sql); sql.AppendFormat("INSERT INTO temp_player_units (category, principal_id, amount) ", new object[0]); sql.AppendFormat("(SELECT 'airbuilt', principal_id, SUM(built) FROM player_units WHERE unit_id like ('URA%') OR unit_id like ('UEA%') OR unit_id like ('UAA%') GROUP BY principal_id);", new object[0]); ExecuteQuery(sql); sql.AppendFormat("INSERT INTO temp_player_units (category, principal_id, amount) ", new object[0]); sql.AppendFormat("(SELECT 'landbuilt', principal_id, SUM(built) FROM player_units WHERE unit_id like ('URL%') OR unit_id like ('UEL%') OR unit_id like ('UAL%') GROUP BY principal_id);", new object[0]); ExecuteQuery(sql); sql.AppendFormat("INSERT INTO temp_player_units (category, principal_id, amount) ", new object[0]); sql.AppendFormat("(SELECT 'seabuilt', principal_id, SUM(built) FROM player_units WHERE unit_id like ('URS%') OR unit_id like ('UES%') OR unit_id like ('UAS%') GROUP BY principal_id);", new object[0]); ExecuteQuery(sql); sql.AppendFormat("INSERT INTO temp_player_units (category, principal_id, amount) ", new object[0]); sql.AppendFormat("(SELECT 'built', principal_id, SUM(built) FROM player_units GROUP BY principal_id);", new object[0]); ExecuteQuery(sql); sql.AppendFormat("INSERT INTO temp_player_units (category, principal_id, amount) ", new object[0]); sql.AppendFormat("(SELECT 'killed', principal_id, SUM(killed) FROM player_units GROUP BY principal_id);", new object[0]); ExecuteQuery(sql); sql.AppendFormat("INSERT INTO temp_player_units (category, principal_id, amount) ", new object[0]); sql.AppendFormat("(SELECT 'civkilled', principal_id, SUM(killed) FROM player_units WHERE unit_id like ('URC%') OR unit_id like ('UEC%') OR unit_id like ('UAC%') GROUP BY principal_id);", new object[0]); ExecuteQuery(sql); if (statusProvider != null) { statusProvider.SetStatus("Creating temp ratings table", new object[0]); } sql.AppendFormat("DROP TABLE IF EXISTS temp_ratings_for_awards;", new object[0]); sql.AppendFormat("CREATE TABLE temp_ratings_for_awards SELECT * FROM ratings", new object[0]); ExecuteQuery(sql); sql.AppendFormat("ALTER TABLE temp_ratings_for_awards ADD INDEX temp_ratings_for_awards_ix1 (principal_id, category, team_name)", new object[0]); ExecuteQuery(sql); sql.AppendFormat("ALTER TABLE temp_ratings_for_awards ADD INDEX temp_ratings_for_awards_ix2 (rank, category, principal_id", new object[0]); ExecuteQuery(sql); sql.AppendFormat("ALTER TABLE temp_ratings_for_awards ADD INDEX temp_ratings_for_awards_ix3 (team_name, principal_id, category)", new object[0]); ExecuteQuery(sql); foreach (GPG.Multiplayer.Statistics.Award award in GPG.Multiplayer.Statistics.Award.AllAwards.Values) { if ((award.AchievementQuery == null) || (award.AchievementQuery.Length <= 0)) { continue; } DateTime time3 = DateTime.Now; if (award.AwardSet != null) { if (statusProvider != null) { statusProvider.SetStatus("Calculating achievement status for award: {0}, {1}", new object[] { award.AwardSet.Name, award.AwardDegree }); } } else if (statusProvider != null) { statusProvider.SetStatus("Calculating achievement status for award: {0}, {1}", new object[] { "Unknown Award Set", award.AwardDegree }); } string str3 = award.AchievementQuery.Replace("ratings", "temp_ratings_for_awards"); sql.AppendFormat("INSERT INTO {0} (player_id, award_id, is_achieved) (SELECT player_id, {1}, 1 FROM temp_player_ids WHERE ({2}) > 0);", str, award.ID, str3); if (statusProvider != null) { statusProvider.SetStatus(sql.ToString(), new object[0]); } ExecuteQuery(sql); TimeSpan span2 = (TimeSpan) (DateTime.Now - time3); if (statusProvider != null) { statusProvider.SetStatus("Finished calculating award: {0}, {1} in {2} seconds", new object[] { award.AwardSet.Name, award.AwardDegree, span2.TotalSeconds }); } Thread.Sleep(500); } if (statusProvider != null) { statusProvider.SetStatus("Clearing player_display_awards where the award no longer exists for the player.", new object[0]); } sql.AppendFormat("UPDATE player_display_awards SET ", new object[0]); sql.AppendFormat("award1 = (SELECT award_id FROM {0} WHERE player_display_awards.player_id = {0}.player_id AND award1 = award_id LIMIT 1), ", str); sql.AppendFormat("award2 = (SELECT award_id FROM {0} WHERE player_display_awards.player_id = {0}.player_id AND award2 = award_id LIMIT 1), ", str); sql.AppendFormat("award3 = (SELECT award_id FROM {0} WHERE player_display_awards.player_id = {0}.player_id AND award3 = award_id LIMIT 1) ", str); ExecuteQuery(sql); if (statusProvider != null) { statusProvider.SetStatus("Moving temp data to live data", new object[0]); } sql.AppendFormat("RENAME TABLE player_award TO {0}, {1} TO player_award;", str2, str); ExecuteQuery(sql); if (statusProvider != null) { statusProvider.SetStatus("Inserting Player Display record for new players.", new object[0]); } sql.AppendFormat("INSERT INTO player_display_awards (player_id) SELECT principal AS player_id FROM principal_info where (SELECT COUNT(*) FROM player_display_awards WHERE player_id = principal) = 0", new object[0]); ExecuteQuery(sql); } catch (Exception exception) { ErrorLog.WriteLine("Failed to calculate player awards due to the following exception:", new object[0]); ErrorLog.WriteLine(exception); } finally { if (statusProvider != null) { statusProvider.SetStatus("Deleting old data", new object[0]); } sql.AppendFormat("DROP TABLE IF EXISTS {0};", str2); sql.AppendFormat("DROP TABLE IF EXISTS old_player_avatar;", new object[0]); sql.AppendFormat("DROP TABLE IF EXISTS temp_player_ids;", new object[0]); sql.AppendFormat("DROP TABLE IF EXISTS temp_ratings_for_awards;", new object[0]); ExecuteQuery(sql); sql.AppendFormat("DROP TABLE IF EXISTS tournament_final_results;", new object[0]); sql.AppendFormat("RENAME TABLE temp_tournament_results TO tournament_final_results", new object[0]); ExecuteQuery(sql); TimeSpan span3 = (TimeSpan) (DateTime.Now - now); if (statusProvider != null) { statusProvider.SetStatus("Awards processing completed in {0} seconds", 0x1388, new object[] { span3.TotalSeconds }); } } }
public static void CalculateAvatars(IStatusProvider statusProvider) { DateTime now = DateTime.Now; StringBuilder sql = new StringBuilder(100); ClearCachedData(); try { if (statusProvider != null) { statusProvider.SetStatus("Clearing old temp data if it exists", new object[0]); } Thread.Sleep(500); sql.AppendFormat("DROP TABLE IF EXISTS temp_player_ids;", new object[0]); sql.AppendFormat("DROP TABLE IF EXISTS old_player_avatar;", new object[0]); sql.AppendFormat("DROP TABLE IF EXISTS temp_player_avatar;", new object[0]); sql.AppendFormat("DROP TABLE IF EXISTS temp_tournament_results;", new object[0]); sql.AppendFormat("CREATE TABLE temp_player_ids (", new object[0]); sql.AppendFormat("player_id INTEGER UNSIGNED NOT NULL,", new object[0]); sql.AppendFormat("PRIMARY KEY(player_id)", new object[0]); sql.AppendFormat(") SELECT principal AS player_id FROM principal_info;", new object[0]); ExecuteQuery(sql); sql.AppendFormat("CREATE TABLE temp_tournament_results ", new object[0]); sql.AppendFormat("SELECT tournaments.tournament_id, new.principal_id, ", new object[0]); sql.AppendFormat("(SELECT count(*) FROM tournament_round old WHERE old.tournament_id = tournaments.tournament_id AND ", new object[0]); sql.AppendFormat("old.round = tournaments.round AND ", new object[0]); sql.AppendFormat("( (old.wins + (0.5 * old.draws)) > (new.wins + (0.5 * new.draws)) OR ", new object[0]); sql.AppendFormat("( (old.wins + (0.5 * old.draws)) = (new.wins + (0.5 * new.draws)) AND (old.seed < new.seed) ) ) ) + 1 as finish_pos ", new object[0]); sql.AppendFormat("FROM tournaments, tournament_round new ", new object[0]); sql.AppendFormat("WHERE ", new object[0]); sql.AppendFormat("tournaments.tournament_id = new.tournament_id ", new object[0]); sql.AppendFormat("AND ", new object[0]); sql.AppendFormat("tournaments.round = new.round ", new object[0]); sql.AppendFormat("ORDER BY tournaments.tournament_id DESC, (wins + (0.5 * draws)) DESC, seed ASC;", new object[0]); sql.AppendFormat("ALTER TABLE temp_tournament_results ADD index temp_tournament_results_ix1 (principal_id, finish_pos);", new object[0]); ExecuteQuery(sql); if (statusProvider != null) { statusProvider.SetStatus("Creating temp schema for avatars", new object[0]); } Thread.Sleep(500); sql.AppendFormat("CREATE TABLE temp_player_avatar (", new object[0]); sql.AppendFormat("player_avatar_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,", new object[0]); sql.AppendFormat("player_id INTEGER UNSIGNED NULL,", new object[0]); sql.AppendFormat("avatar_id INTEGER UNSIGNED NULL,", new object[0]); sql.AppendFormat("manual_assignment BOOL NULL DEFAULT 0,", new object[0]); sql.AppendFormat("PRIMARY KEY(player_avatar_id),", new object[0]); sql.AppendFormat("UNIQUE INDEX temp_player_avatar_index3199(player_id, avatar_id),", new object[0]); sql.AppendFormat("INDEX temp_player_avatar_index3203(avatar_id),", new object[0]); sql.AppendFormat("INDEX temp_player_avatar_index3208(manual_assignment)", new object[0]); sql.AppendFormat(") SELECT * FROM player_avatar WHERE manual_assignment = 1;", new object[0]); ExecuteQuery(sql); foreach (Avatar avatar in AllAvatars.Values) { if (((avatar.AchievementQuery != null) && (avatar.AchievementQuery.Length >= 1)) && (avatar.AchievementQuery != "(null)")) { DateTime time2 = DateTime.Now; if (statusProvider != null) { statusProvider.SetStatus("Calculating achievement status for avatar: {0}", new object[] { avatar.Description }); } sql.AppendFormat("INSERT INTO temp_player_avatar (player_id, avatar_id, manual_assignment) (SELECT player_id, {0}, 0 FROM temp_player_ids WHERE ({1}) > 0);", avatar.ID, avatar.AchievementQuery); ExecuteQuery(sql); TimeSpan span = (TimeSpan) (DateTime.Now - time2); if (statusProvider != null) { statusProvider.SetStatus("Finished calculating avatar: {0} in {1} seconds", new object[] { avatar.Description, span.TotalSeconds }); } Thread.Sleep(500); } } if (statusProvider != null) { statusProvider.SetStatus("Removing unachieved display avatars", new object[0]); } sql.AppendFormat("UPDATE player_display_awards SET avatar = 0 WHERE ", new object[0]); sql.AppendFormat("(SELECT COUNT(*) FROM temp_player_avatar WHERE ", new object[0]); sql.AppendFormat("temp_player_avatar.player_id = player_display_awards.player_id AND ", new object[0]); sql.AppendFormat("temp_player_avatar.avatar_id = player_display_awards.avatar) = 0;", new object[0]); ExecuteQuery(sql); if (statusProvider != null) { statusProvider.SetStatus("Moving temp avatar data to live data", new object[0]); } Thread.Sleep(0x3e8); sql.AppendFormat("RENAME TABLE player_avatar TO old_player_avatar, temp_player_avatar TO player_avatar;", new object[0]); ExecuteQuery(sql); } catch (Exception exception) { ErrorLog.WriteLine("Failed to calculate player awards due to the following exception:", new object[0]); ErrorLog.WriteLine(exception); } finally { if (statusProvider != null) { statusProvider.SetStatus("Deleting old data", new object[0]); } sql.AppendFormat("DROP TABLE IF EXISTS old_player_avatar;", new object[0]); sql.AppendFormat("DROP TABLE IF EXISTS temp_player_ids;", new object[0]); sql.AppendFormat("DROP TABLE IF EXISTS temp_tournament_results;", new object[0]); ExecuteQuery(sql); TimeSpan span2 = (TimeSpan) (DateTime.Now - now); if (statusProvider != null) { statusProvider.SetStatus("Awards processing completed in {0} seconds", 0x1388, new object[] { span2.TotalSeconds }); } } }
public bool SaveDownload(IStatusProvider statusProvider) { if (!base.ContentType.CurrentUserCanDownload) { if (statusProvider != null) { statusProvider.SetStatus("<LOC>You do not have permission to download this content", new object[0]); } return false; } try { string path = this.GetDownloadPath() + @"\content.partial"; if (!System.IO.File.Exists(path)) { ErrorLog.WriteLine("The expected download file: {0} was not found.", new object[] { path }); if (statusProvider != null) { statusProvider.SetStatus("<LOC>An error occurred while downloading file, please try again.", 0xbb8, new object[0]); } return false; } statusProvider.SetStatus("<LOC>Extracting File(s)...", new object[0]); Compression.Unzip(path); Thread.Sleep(50); DateTime now = DateTime.Now; while (System.IO.File.Exists(path)) { try { System.IO.File.Delete(path); } catch { if ((DateTime.Now - now) > TimeSpan.FromSeconds(5.0)) { break; } Thread.Sleep(50); } } return true; } catch (Exception exception) { ErrorLog.WriteLine(exception); return false; } }
public static void UploadContent(IAdditionalContent content, IStatusProvider initialForm) { if (!content.CurrentUserIsOwner && !content.IsContentUnique()) { if (initialForm != null) { initialForm.SetStatus("<LOC>Unable to upload, a {0} by this name already exists", 0xbb8, new object[] { content.ContentType.SingularDisplayName.ToLower() }); } } else if (!content.CurrentUserCanUpload) { if (initialForm != null) { initialForm.SetStatus("<LOC>You do not have permission to upload this content type.", 0xbb8, new object[0]); } } else { mUploadingContent = true; ThreadPool.QueueUserWorkItem(delegate (object s) { content.Version++; IVaultOperation activityMonitor = null; if ((content is IFTPInfo) && (content as IFTPInfo).UploadFTP()) { activityMonitor = new VaultFTPUploadOperation(content); } else { activityMonitor = new VaultUploadOperation(content); } if (BeginUploadContent != null) { BeginUploadContent(new ContentOperationCallbackArgs(content, activityMonitor)); } activityMonitor.OperationFinished += new ContentOperationCallback(AdditionalContent.UploadOperation_Finished); activityMonitor.Start(); }); } }
public static void DownloadUpdate(int contentId, IStatusProvider statusForm) { if (DownloadsEnabled && !IsDownloadingContent(contentId)) { if (statusForm != null) { statusForm.SetStatus(Loc.Get("<LOC>Locating content..."), new object[0]); } int @int = new QuazalQuery("GetContentTypeById", new object[] { contentId }).GetInt(); if (@int < 0) { if (statusForm != null) { statusForm.SetStatus("<LOC>An error occurred while downloading file, please try again.", 0xbb8, new object[0]); } } else { IAdditionalContent content; if (!GPG.Multiplayer.Client.Vaulting.ContentType.FromID(@int).CreateInstance().FromID(contentId, out content)) { if (statusForm != null) { statusForm.SetStatus("<LOC>An error occurred while downloading file, please try again.", 0xbb8, new object[0]); } } else { DownloadContent(content, statusForm); } } } }
public static void DownloadContent(IAdditionalContent content, IStatusProvider statusForm) { if (DownloadsEnabled && !IsDownloadingContent(content)) { if (!content.CurrentUserCanDownload) { if (statusForm != null) { statusForm.SetStatus("<LOC>You do not have permission to download this content.", 0xbb8, new object[0]); } } else { ThreadPool.QueueUserWorkItem(delegate (object s) { int @int = ConfigSettings.GetInt("MaxDailyVaultDownload", 5); if (!User.Current.IsAdmin && (DailyDownloadCount >= @int)) { string message = string.Format(Loc.Get("<LOC>You have reached the maximum number of downloads allowed per day. You are allowed up to {0} downloads in any 24 hour period."), @int); if (statusForm == null) { DlgMessage.ShowDialog(message); } else { statusForm.SetStatus(message, 0x1388, new object[0]); } } else { IVaultOperation operation; if (!content.HasVolunteeredForDownload) { if (DlgMessage.ShowDialog("<LOC>To download this file you must first agree to its legal conditions by volunteering to download it. Click OK to continue to the volunteer form.") != DialogResult.OK) { return; } OGen0 method = null; VolunteerEffort effort; if (new QuazalQuery("GetVolunteerEffortByName", new object[] { content.DownloadVolunteerEffort }).GetObject<VolunteerEffort>(out effort)) { if (method == null) { method = delegate { if (new DlgVolunteer(effort).ShowDialog() == DialogResult.OK) { content.HasVolunteeredForDownload = true; return true; } return false; }; } if (!((bool) Program.MainForm.Invoke(method))) { return; } } } mDownloadTarget = content; if ((content.ContentDependencies != null) && (content.ContentDependencies.Length > 0)) { List<int> missing = new List<int>(); Dictionary<int, IAdditionalContent> dictionary = new Dictionary<int, IAdditionalContent>(MyContent.Count); foreach (IAdditionalContent content1 in MyContent) { dictionary[content1.ID] = content1; } foreach (int num2 in content.ContentDependencies) { if (!dictionary.ContainsKey(num2)) { missing.Add(num2); } } if (missing.Count > 0) { DialogResult result = DialogResult.No; Program.MainForm.Invoke((VGen0)delegate { result = new DlgYesNoCancel("<LOC>Content Dependency", string.Format(Loc.Get("<LOC>The requested {0} is dependent on {1} additional vaulted download(s) that you do not have and may not operate properly without them. GPGnet can download these for you now, or you can manually download them later. Do you want GPGnet to download these dependencies now?"), content.ContentType.SingularDisplayName.ToLower(), missing.Count)).ShowDialog(); }); switch (result) { case DialogResult.Yes: foreach (int num3 in missing) { DownloadContent(num3, statusForm); } break; case DialogResult.Cancel: return; } } } if (!content.IsDirectHTTPDownload) { operation = new VaultDownloadOperation(content); } else { operation = new VaultDirectDownloadOperation(content); } if (BeginDownloadContent != null) { BeginDownloadContent(new ContentOperationCallbackArgs(content, operation)); } operation.OperationFinished += new ContentOperationCallback(AdditionalContent.DownloadOperation_Finished); operation.Start(); } }); } } }
public static void CheckForUpdates(IAdditionalContent content, IStatusProvider statusProvider) { if ((!CheckingforUpdates && DownloadsEnabled) && !IsDownloadingContent(content)) { ThreadPool.QueueUserWorkItem(delegate (object s) { try { mCheckingForUpdates = true; statusProvider.SetStatus("<LOC>Checking for updates...", new object[0]); if (BeginCheckForUpdates != null) { BeginCheckForUpdates(new ContentOperationCallbackArgs(content, null)); } DataList data = new QuazalQuery("GetLatestContentVersion", new object[] { content.Name, content.TypeID }).GetData(); if (data.Count < 1) { statusProvider.SetStatus("<LOC>No updates found.", 0xbb8, new object[0]); mCheckingForUpdates = false; if (FinishCheckForUpdates != null) { FinishCheckForUpdates(new ContentOperationCallbackArgs(content, null, false, new object[0])); } } else { int contentId = int.Parse(data[0]["content_id"]); int num2 = int.Parse(data[0]["version"]); if ((int.Parse(data[0]["has_current"]) > 0) || (content.Version == num2)) { statusProvider.SetStatus("<LOC>{0} is up to date.", 0xbb8, new object[] { content.Name }); mCheckingForUpdates = false; if (FinishCheckForUpdates != null) { FinishCheckForUpdates(new ContentOperationCallbackArgs(content, null, true, new object[0])); } } else { statusProvider.SetStatus("<LOC>Update found, preparing to download...", new object[0]); FinishDownloadContent = (ContentOperationCallback) Delegate.Combine(FinishDownloadContent, new ContentOperationCallback(AdditionalContent.AdditionalContent_FinishDownloadContent)); DownloadUpdate(contentId, statusProvider); mCheckingForUpdates = false; if (FinishCheckForUpdates != null) { FinishCheckForUpdates(new ContentOperationCallbackArgs(content, null, true, new object[0])); } } } } catch (Exception exception) { ErrorLog.WriteLine(exception); statusProvider.SetStatus("<LOC>An error occurred while checking for updates, please try again.", 0xbb8, new object[0]); mCheckingForUpdates = false; if (FinishCheckForUpdates != null) { FinishCheckForUpdates(new ContentOperationCallbackArgs(content, null, true, new object[0])); } } }); } }
public bool SaveDownload(IStatusProvider statusProvider) { try { string unzipPath; if (this.ExtractToSupcom) { if (((GameInformation.SelectedGame.GameLocation == null) || (GameInformation.SelectedGame.GameLocation.Length < 1)) || !File.Exists(GameInformation.SelectedGame.GameLocation)) { GameInformation.SelectedGame.GameLocation = null; if (!Program.MainForm.LocateExe("SupremeCommander", true)) { return false; } } unzipPath = Path.GetDirectoryName(GameInformation.SelectedGame.GameLocation); } else { unzipPath = this.GetDownloadPath(); } string path = string.Format(@"{0}\content.partial", this.GetDownloadPath()); if (!File.Exists(path)) { ErrorLog.WriteLine("The expected download file: {0} was not found.", new object[] { path }); if (statusProvider != null) { statusProvider.SetStatus("<LOC>An error occurred while downloading file, please try again.", 0xbb8, new object[0]); } return false; } statusProvider.SetStatus("<LOC>Extracting File(s)...", new object[0]); Compression.Unzip(path, this.GetDownloadPath()); File.Delete(path); if (this.ExtractToSupcom) { string sourceFileName = Path.Combine(this.GetDownloadPath(), this.ExeName); foreach (string str3 in Directory.GetFiles(this.GetDownloadPath())) { if (str3 == sourceFileName) { if (File.Exists(Path.Combine(unzipPath, this.ExeName))) { File.Delete(Path.Combine(unzipPath, this.ExeName)); } File.Move(sourceFileName, Path.Combine(unzipPath, this.ExeName)); } } FileUtil.CreateShortcut(Path.Combine(unzipPath, this.ExeName), Path.Combine(this.GetDownloadPath(), base.Name.Trim(Path.GetInvalidPathChars()))); } Program.MainForm.BeginInvoke((VGen0)delegate { if (new DlgYesNo(Program.MainForm, "<LOC>Create Shortcut?", "<LOC>Would you like to create a desktop shortcut this tool?").ShowDialog() == DialogResult.Yes) { string str = string.Format("{0} v{1}", this.Name, this.Version).Trim(Path.GetInvalidPathChars()); FileUtil.CreateShortcut(Path.Combine(unzipPath, this.ExeName), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), str)); } }); return true; } catch (Exception exception) { ErrorLog.WriteLine(exception); return false; } }