private void cmdImport_Click(object sender, EventArgs e) { try { Models.Build build = null; string data = txtShareCode.Text; if (data.StartsWith("sc2bo://")) { data = data.Substring(8); } try { build = Models.Build.ParseSALT(new SALT(data)); } catch (Exception) { } if (build == null) { build = Models.Build.ParseBase64(data); } frmImportBuild import = new frmImportBuild(build); if (import.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Program.BuildsDB.Add(build); Program.SaveBuildsXML(); this.DialogResult = System.Windows.Forms.DialogResult.OK; } Close(); } catch (Exception ex) { MessageBox.Show(string.Format("Failed to import build:\r\n\r\n{0}", ex.ToString()), "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected override void WndProc(ref Message m) { if (m.Msg == Win32.WM_SHOWBON) { ShowWindow(); } else if (m.Msg == Win32.WM_BONIMPORT) { string[] files = System.IO.Directory.GetFiles(Program.DataDirectory, "*.import"); foreach (string file in files) { string data = System.IO.File.ReadAllText(file); System.IO.File.Delete(file); try { Build build = Build.ParseBase64(data); if (build != null) { ShowWindow(); frmImportBuild import = new frmImportBuild(build); if (import.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Program.BuildsDB.Add(build); Program.SaveBuildsXML(); PopulateBuilds(); } } } catch { } } } else { base.WndProc(ref m); } }
public frmMain(string importCode = null) { Instance = this; InitializeComponent(); lvwColumnSorter = new ListViewColumnSorter(); lvBuilds.ListViewItemSorter = lvwColumnSorter; lvwColumnSorter.SortColumn = 0; lvwColumnSorter.Order = SortOrder.Ascending; cbRace.ItemHeight = 16; cbRace.Items.Add(new EXControls.EXComboBox.EXItem("Any")); cbRace.Items.Add(new EXControls.EXComboBox.EXImageItem("Terran", SC2Scrapbook.Properties.Resources.terran)); cbRace.Items.Add(new EXControls.EXComboBox.EXImageItem("Protoss", SC2Scrapbook.Properties.Resources.protoss)); cbRace.Items.Add(new EXControls.EXComboBox.EXImageItem("Zerg", SC2Scrapbook.Properties.Resources.zerg)); cbVsRace.Items.Add(new EXControls.EXComboBox.EXItem("Any")); cbVsRace.Items.Add(new EXControls.EXComboBox.EXImageItem("Terran", SC2Scrapbook.Properties.Resources.terran)); cbVsRace.Items.Add(new EXControls.EXComboBox.EXImageItem("Protoss", SC2Scrapbook.Properties.Resources.protoss)); cbVsRace.Items.Add(new EXControls.EXComboBox.EXImageItem("Zerg", SC2Scrapbook.Properties.Resources.zerg)); cbVsRace.Items.Add(new EXControls.EXComboBox.EXImageItem("Random", SC2Scrapbook.Properties.Resources.random)); cbMatchup.Items.Add(new EXControls.EXComboBox.EXImageItem("TvT", SC2Scrapbook.Properties.Resources.terran)); cbMatchup.Items.Add(new EXControls.EXComboBox.EXImageItem("TvP", SC2Scrapbook.Properties.Resources.terran)); cbMatchup.Items.Add(new EXControls.EXComboBox.EXImageItem("TvZ", SC2Scrapbook.Properties.Resources.terran)); cbMatchup.Items.Add(new EXControls.EXComboBox.EXImageItem("TvX", SC2Scrapbook.Properties.Resources.terran)); cbMatchup.Items.Add(new EXControls.EXComboBox.EXImageItem("PvT", SC2Scrapbook.Properties.Resources.protoss)); cbMatchup.Items.Add(new EXControls.EXComboBox.EXImageItem("PvP", SC2Scrapbook.Properties.Resources.protoss)); cbMatchup.Items.Add(new EXControls.EXComboBox.EXImageItem("PvZ", SC2Scrapbook.Properties.Resources.protoss)); cbMatchup.Items.Add(new EXControls.EXComboBox.EXImageItem("PvX", SC2Scrapbook.Properties.Resources.protoss)); cbMatchup.Items.Add(new EXControls.EXComboBox.EXImageItem("ZvT", SC2Scrapbook.Properties.Resources.zerg)); cbMatchup.Items.Add(new EXControls.EXComboBox.EXImageItem("ZvP", SC2Scrapbook.Properties.Resources.zerg)); cbMatchup.Items.Add(new EXControls.EXComboBox.EXImageItem("ZvZ", SC2Scrapbook.Properties.Resources.zerg)); cbMatchup.Items.Add(new EXControls.EXComboBox.EXImageItem("ZvX", SC2Scrapbook.Properties.Resources.zerg)); PopulateBuilds(); if (!Configuration.Instance.FirstRun) { if ((Configuration.Instance.MainHeight != 0) && (Configuration.Instance.MainWidth != 0)) { Height = Configuration.Instance.MainHeight; Width = Configuration.Instance.MainWidth; } } foreach (Patch patch in Program.PatchList) { cbPatch.Items.Add(new EXControls.EXComboBox.EXItem(patch.ToString())); } if (cbPatch.Items.Count > 0) { cbPatch.SelectedIndex = 0; } if (importCode != null) { MessageBox.Show(importCode); var build = Build.ParseBase64(importCode); if (build != null) { frmImportBuild import = new frmImportBuild(build); if (import.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Program.BuildsDB.Add(build); Program.SaveBuildsXML(); PopulateBuilds(); } } } try { System.Net.WebClient c = new System.Net.WebClient(); c.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); string update = c.DownloadString("https://bitbucket.org/Veritasimo/sc2-scrapbook/downloads/version.txt"); if (!string.IsNullOrEmpty(update)) { string[] thisVersion = Properties.Resources.version.Split('|'); string[] newVersion = update.Split('|'); if (newVersion.Length == 3) { int newVersionNumber = 0; int oldVersionNumber = int.Parse(thisVersion[0]); if (int.TryParse(newVersion[0], out newVersionNumber)) { if (newVersionNumber > oldVersionNumber) { lbUpdate.Text = string.Format("Update Available ({0})", newVersion[1]); lbUpdate.Tag = newVersion[2]; lbUpdate.Visible = true; } } } } } catch { } foreach (ToolStripMenuItem item in zergToolStripMenuItem3.DropDownItems) { item.Click += new EventHandler(insertIconMenuClick); } foreach (ToolStripMenuItem item in protossToolStripMenuItem3.DropDownItems) { item.Click += new EventHandler(insertIconMenuClick); } foreach (ToolStripMenuItem item in terranToolStripMenuItem3.DropDownItems) { item.Click += new EventHandler(insertIconMenuClick); } foreach (ToolStripMenuItem item in zergToolStripMenuItem4.DropDownItems) { item.Click += new EventHandler(insertIconMenuClick); } foreach (ToolStripMenuItem item in protossToolStripMenuItem4.DropDownItems) { item.Click += new EventHandler(insertIconMenuClick); } foreach (ToolStripMenuItem item in terranToolStripMenuItem4.DropDownItems) { item.Click += new EventHandler(insertIconMenuClick); } foreach (ToolStripMenuItem item in zergToolStripMenuItem5.DropDownItems) { if (!item.HasDropDownItems) { item.Click += new EventHandler(insertIconMenuClick); } else { foreach (ToolStripMenuItem subitem in item.DropDownItems) { subitem.Click += new EventHandler(insertIconMenuClick); } } } foreach (ToolStripMenuItem item in protossToolStripMenuItem5.DropDownItems) { if (!item.HasDropDownItems) { item.Click += new EventHandler(insertIconMenuClick); } else { foreach (ToolStripMenuItem subitem in item.DropDownItems) { subitem.Click += new EventHandler(insertIconMenuClick); } } } foreach (ToolStripMenuItem item in terranToolStripMenuItem5.DropDownItems) { if (!item.HasDropDownItems) { item.Click += new EventHandler(insertIconMenuClick); } else { foreach (ToolStripMenuItem subitem in item.DropDownItems) { subitem.Click += new EventHandler(insertIconMenuClick); } } } #if DEBUG button1.Visible = true; button1.Enabled = true; #endif }