private void Form1_Load_1(object sender, EventArgs e) { MtgController.baseform = this; DirectoryExtras.SetCurrentDirectoryToDefault(); Licensing.LicensingForm(this, menuStrip1, HelpString, OtherText); ResetProgress(); SearchType.Items.AddRange(Enum.GetValues(typeof(SearchType)).Cast <object>().ToArray()); SearchType.SelectedIndex = 0; PrintType.Items.AddRange(Enum.GetValues(typeof(PrintModes)).Cast <object>().ToArray()); PrintType.SelectedIndex = 0; LoadConfig(); if (Directory.Exists(CardHolder.ImageFolder) == false) { Directory.CreateDirectory(CardHolder.ImageFolder); } }
/// <summary> /// Updates the application. /// </summary> /// <param name="dsd">The DSD.</param> private static void UpdateApplication(LicensingDetails dsd) { string folder; string localfile; //we need the exe file for later execution var exefile = ""; string exefolder; try { //0: reset current directory in case it was changed Directory.SetCurrentDirectory(Application.StartupPath); //1: Get the online files folder = _sd.AppName + "v" + DateTime.Now.Ticks; Directory.CreateDirectory(folder); } catch (Exception ex) { MessageBox.Show("Error while creating the temporary folder\n:" + ex); return; } try { var client = new WebClient(); localfile = dsd.FileLocation.Substring(dsd.FileLocation.LastIndexOf('/') + 1); client.DownloadFile(dsd.FileLocation, localfile); } catch (Exception ex) { MessageBox.Show("Error while downloading new files\n:" + ex); return; } try { var myname = AppDomain.CurrentDomain.FriendlyName; const string vshost = ".vshost."; //remove .vshost for testing if (myname.Contains(vshost)) { myname = myname.Replace(vshost, "."); } //2.1 unpack ZipExtras.ExtractZipFile(localfile, folder); //2.2 find exe foreach (var f in DirectoryExtras.GetFilesRecursive(folder)) { if (f.Contains(".exe")) { exefile = f; } if (f.EndsWith(myname)) { break; } } const string br = "\\"; exefolder = ""; //ignore everything above this dir while (exefile.Length > 0) { var c = StringExtras.ContainsSubStringCount(exefile, br); if (c > 0) { var s = exefile.Substring(0, exefile.IndexOf(br, StringComparison.Ordinal)); exefolder += s + br; exefile = exefile.Substring(exefile.IndexOf(br, StringComparison.Ordinal) + 1); } else { break; } } } catch (Exception ex) { MessageBox.Show("Error while unzipping new files\n:" + ex); return; } //move folder/* to the local dir //delete the zip file //delete folder remnants //start the exefile we found before var operations = "move /Y \"" + exefolder + "\"\\* . " + "& del /Q \"" + localfile + "\" " + "& rmdir /Q /S \"" + folder + "\" " + "& start \"\" \"" + exefile + "\" "; RunCommands(operations); //4: Kill process Application.Exit(); }