private void setupWizard_Load(object sender, EventArgs e) { if (!_arguments.Contains("/uninstall")) { if (_context.Product is productBeta && !_context.isUpgrade) { showPage(typeof(stpBeta)); } else if (_context.isUpgrade) { _context.installationDirectory = ProgramsAndFeaturesHelper.installationDirectory(_context.Product); showPage(typeof(stpUpgrade)); } else { showPage(typeof(stpLicense)); } } else { //Anwendung deinstallieren //Installationsverzeichnis setzen _context.installationDirectory = ProgramsAndFeaturesHelper.installationDirectory(_context.Product); showPage(typeof(stpWelcomeUninstall)); } }
private bool initializeSetup() { //BETA RTM SWITCH _context = new setupContext { Product = new productBeta() }; //Setupseiten initialisieren _setupPages = new Dictionary <Type, ISetupPage> { { typeof(stpBeta), new stpBeta() }, { typeof(stpLicense), new stpLicense() }, { typeof(stpDonate), new stpDonate() }, { typeof(stpOptions), new stpOptions() }, { typeof(stpInstall), new stpInstall() }, { typeof(stpInterrupted), new stpInterrupted() }, { typeof(stpInstalled), new stpInstalled() }, { typeof(stpWelcomeUninstall), new stpWelcomeUninstall() }, { typeof(stpUninstall), new stpUninstall() }, { typeof(stpUninstalled), new stpUninstalled() }, { typeof(stpUpgrade), new stpUpgrade() } }; _context.isUpgrade = (ProgramsAndFeaturesHelper.isInstalled(_context.Product) && ProgramsAndFeaturesHelper.getCurrentVersion(_context.Product) < Assembly.GetExecutingAssembly().GetName().Version); if (ProgramsAndFeaturesHelper.isInstalled(_context.Product) && ProgramsAndFeaturesHelper.getCurrentVersion(_context.Product) == Assembly.GetExecutingAssembly().GetName().Version&& !_arguments.Contains("/uninstall")) { if (MessageBox.Show(string.Format("Es ist bereits eine identische Version von {0} installiert.\r\nMöchten Sie das Setup trotzdem starten?", _context.Product.Product), _context.Product.Product, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No) { return(false); } } return(true); }
//Kopieren der Dateien beendet private void bgwCopy_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { taskBarManager.Instance.setTaskBarProgressState(taskBarProgressState.NoProgress); if (e.Result == null) { // mit Erfolg try { //Verknüpfungen erstellen string administrationPath = Path.Combine(Context.installationDirectory, Context.Product.mainExecutable); // Auf dem Desktop if (Context.createDesktopShortcut) { var shortcutDesktop = new ShellShortcut(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "updateSystem.NET Administration.lnk")) { IconIndex = 0, IconPath = administrationPath, Path = administrationPath }; shortcutDesktop.Save(); } //Im Startmenu if (Context.createStartMenuShortcut) { var shortcutStartMenu = new ShellShortcut(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "updateSystem.NET Administration.lnk")) { IconIndex = 0, IconPath = administrationPath, Path = administrationPath }; shortcutStartMenu.Save(); } //Uninstalldaten in die Registry schreiben if (IsUserAnAdmin()) { ProgramsAndFeaturesHelper.Add(Context); } //Installer zwecks deinstallation ins Programmverzeichnis kopieren File.Copy(Application.ExecutablePath, Path.Combine(Context.installationDirectory, Context.Product.setupName), true); //Nur in Releaseversion Dateitypen registrieren if (Context.Product.GetType() == typeof(productRTM)) { //Neuen UDPROJX-Type registrieren FileAssociation.Associate( ".udprojx", Context.Product.applicationID, "updateSystem.NET Projektdatei", Path.Combine(Context.installationDirectory, "Project.ico"), administrationPath); //Alten UDPROJ-Type registrieren wenn dieser nicht bereits von der alten Installation registriert wurde if (!FileAssociation.IsAssociated(".udproj")) { FileAssociation.Associate( ".udproj", Context.Product.applicationID, "Alte updateSystem.NET Projektdatei", Path.Combine(Context.installationDirectory, "Project.ico"), administrationPath); } //Shell aktualisieren FileAssociation.refreshDesktop(); } //"Fertig"-Seite anzeigen onChangePage(new changePageEventArgs(typeof(stpInstalled))); } catch (Exception exc) { Context.setupException = exc; onChangePage(new changePageEventArgs(typeof(stpInterrupted))); } } else { // mit Exception Context.setupException = (e.Result as Exception); onChangePage(new changePageEventArgs(typeof(stpInterrupted))); } }
private void bgwUninstall_DoWork(object sender, DoWorkEventArgs e) { var context = (e.Argument as setupContext); try { string baseDir = AppDomain.CurrentDomain.BaseDirectory; //Zu entfernende Dateien ermitteln string[] files = Directory.GetFiles(baseDir, "*", SearchOption.AllDirectories); int currentFile = 0; //Versuchen Dateien zu löschen foreach (string file in files) { try { //Versuchen das native Abbild der Datei zu entfernen if (file.EndsWith(".exe") || file.EndsWith(".dll")) { nativeImages.Uninstall(file); } File.Delete(file); currentFile++; bgwUninstall.ReportProgress(Percent(currentFile, files.Length)); } catch { } } //Programm aus der Systemregistrierung entfernen ProgramsAndFeaturesHelper.Remove(context.Product); //Settings löschen if (context.removeSettings) { string settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "updateSystem.NET"); if (Directory.Exists(settingsPath)) { Directory.Delete(settingsPath, true); } } //Verknüpfungen entfernen string scDesktop = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "updateSystem.NET Administration.lnk"); string scStartMenu = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "updateSystem.NET Administration.lnk"); if (File.Exists(scDesktop)) { File.Delete(scDesktop); } if (File.Exists(scStartMenu)) { File.Delete(scStartMenu); } //Dateitypeverknüpfungen entfernen (nur in Releaseversion) if (context.Product.GetType() == typeof(productRTM)) { if (FileAssociation.IsAssociated(".udprojx")) { FileAssociation.DeleteAssociation(".udprojx"); } if (FileAssociation.IsAssociated(".udproj")) { FileAssociation.DeleteAssociation(".udproj"); } FileAssociation.refreshDesktop(); } } catch (Exception exc) { e.Result = exc; } }