private void InitializeForm() { //System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("ru"); //System.Threading.Thread.CurrentThread.CurrentUICulture = culture; InitializeComponent(); this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.IsUnsaved = true; this.UpdateToolStripStatus(); this.ctxMnuRightClick.Items.Add(_localizator.GetLocalizedString("MoveUp"), Properties.Resources.MoveUp); this.ctxMnuRightClick.Items.Add(Localizator.Getinstance().GetLocalizedString("MoveDown"), Properties.Resources.MoveDown); this.ctxMnuRightClick.Items.Add(new ToolStripSeparator()); this.ctxMnuRightClick.Items.Add(_localizator.GetLocalizedString("Delete"), Properties.Resources.DeleteRed); try { if (Properties.Settings.Default.LastUsedFolder == String.Empty || !System.IO.Directory.Exists(Properties.Settings.Default.LastUsedFolder)) { string myDocuments = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments, Environment.SpecialFolderOption.None); Properties.Settings.Default.LastUsedFolder = myDocuments; Properties.Settings.Default.Save(); } this._currentFolder = Properties.Settings.Default.LastUsedFolder; } catch (Exception) { } }
private void SetReturnCodeFromXml(XmlReader reader) { if (reader.ReadToFollowing("Method")) { string method = reader.ReadElementContentAsString(); switch (method) { case "Variable": this.ReturnCodeMethod = ReturnCode.Variable; break; case "Static": this.ReturnCodeMethod = ReturnCode.Static; if (reader.ReadToFollowing("Code")) { int code = reader.ReadElementContentAsInt(); this.StaticCode = code; } else if (this.IsUIEnable) { System.Windows.Forms.MessageBox.Show(Localizator.Getinstance().GetLocalizedString("UnableToSetReturnCodeFromXmlFile")); } else { throw new Exception(Localizator.Getinstance().GetLocalizedString("UnableToSetReturnCodeFromXmlFile")); } break; default: if (this.IsUIEnable) { System.Windows.Forms.MessageBox.Show(Localizator.Getinstance().GetLocalizedString("UnableToSetReturnCodeFromXmlFile")); } else { throw new Exception(Localizator.Getinstance().GetLocalizedString("UnableToSetReturnCodeFromXmlFile")); } break; } } else { if (this.IsUIEnable) { System.Windows.Forms.MessageBox.Show(Localizator.Getinstance().GetLocalizedString("UnableToSetReturnCodeFromXmlFile")); } else { throw new Exception(Localizator.Getinstance().GetLocalizedString("UnableToSetReturnCodeFromXmlFile")); } } }
private void ParseXmlTemplateFile(StreamReader xmlStream) { XmlReader reader = XmlReader.Create(xmlStream); if (!reader.ReadToFollowing("CustomUpdate")) { throw new Exception(Localizator.Getinstance().GetLocalizedString("CustomUpdateFileBadlyFormated")); } else { int version = int.Parse(reader.GetAttribute("Version")); if (version != 2) { throw new Exception("Wrong version. Expected version = 2, this version = " + version); } while (reader.ReadToFollowing("Action")) { reader.ReadToFollowing("ElementType"); GenericAction tempAction = this.GetElementFromXML(reader); if (tempAction != null) { try { Dictionary <string, string> properties = this.GetPropertiesFromXml(reader); tempAction.InitializeProperties(properties); } catch (Exception) { if (this.IsUIEnable) { System.Windows.Forms.MessageBox.Show(Localizator.Getinstance().GetLocalizedString("AnErrorOccursWhileIntializingAction") + tempAction.ToString() + "\r\n" + Localizator.Getinstance().GetLocalizedString("ItWillHaveDefaultValues")); } else { throw new Exception(Localizator.Getinstance().GetLocalizedString("AnErrorOccursWhileIntializingAction") + tempAction.ToString() + "\r\n" + Localizator.Getinstance().GetLocalizedString("ItWillHaveDefaultValues")); } } this.AddAction(tempAction); } } reader.Close(); } }
private GenericAction GetElementFromXML(XmlReader reader) { GenericAction element = null; string elementType = reader.ReadElementContentAsString(); switch (elementType) { case "CustomActions.AddRegKeyAction": element = new AddRegKeyAction(); break; case "CustomActions.AddRegValueAction": element = new AddRegValueAction(); break; case "CustomActions.ChangeRegDataAction": element = new ChangeRegDataAction(); break; case "CustomActions.ChangeServiceAction": element = new ChangeServiceAction(); break; case "CustomActions.CopyFileAction": element = new CopyFileAction(); break; case "CustomActions.CreateFolderAction": element = new CreateFolderAction(); break; case "CustomActions.CreateShortcutAction": element = new CreateShortcutAction(); break; case "CustomActions.CreateTextFileAction": element = new CreateTextFileAction(); break; case "CustomActions.DeleteFileAction": element = new DeleteFileAction(); break; case "CustomActions.DeleteFolderAction": element = new DeleteFolderAction(); break; case "CustomActions.DeleteRegKeyAction": element = new DeleteRegKeyAction(); break; case "CustomActions.DeleteRegValueAction": element = new DeleteRegValueAction(); break; case "CustomActions.DeleteTaskAction": element = new DeleteTaskAction(); break; case "CustomActions.ExecutableAction": element = new ExecutableAction(); break; case "CustomActions.ImportRegFileAction": element = new ImportRegFileAction(); break; case "CustomActions.KillProcessAction": element = new KillProcessAction(); break; case "CustomActions.RebootAction": element = new RebootAction(); break; case "CustomActions.RegisterDLLAction": element = new RegisterDLLAction(); break; case "CustomActions.RenameFileAction": element = new RenameFileAction(); break; case "CustomActions.RenameFolderAction": element = new RenameFolderAction(); break; case "CustomActions.RenameRegKeyAction": element = new RenameRegKeyAction(); break; case "CustomActions.RenameRegValueAction": element = new RenameRegValueAction(); break; case "CustomActions.RunPowershellScriptAction": element = new RunPowershellScriptAction(); break; case "CustomActions.RunVbScriptAction": element = new RunVbScriptAction(); break; case "CustomActions.ShutdownAction": element = new ShutdownAction(); break; case "CustomActions.StartServiceAction": element = new StartServiceAction(); break; case "CustomActions.StopServiceAction": element = new StopServiceAction(); break; case "CustomActions.UninstallMsiProductByGuidAction": element = new UninstallMsiProductByGuidAction(); break; case "CustomActions.UninstallMsiProductByNameAction": element = new UninstallMsiProductByNameAction(); break; case "CustomActions.UnregisterDLLAction": element = new UnregisterDLLAction(); break; case "CustomActions.UnregisterServiceAction": element = new UnregisterServiceAction(); break; case "CustomActions.WaitAction": element = new WaitAction(); break; case "CustomActions.InstallMsiAction": element = new InstallMsiAction(); break; case "CustomActions.ReturnCode": try { this.SetReturnCodeFromXml(reader); } catch (Exception ex) { if (this.IsUIEnable) { System.Windows.Forms.MessageBox.Show(Localizator.Getinstance().GetLocalizedString("UnableToSetReturnCodeFromXmlFile") + "\r\n" + ex.Message); } else { throw new Exception(Localizator.Getinstance().GetLocalizedString("UnableToSetReturnCodeFromXmlFile") + "\r\n" + ex.Message); } } break; default: if (this.IsUIEnable) { System.Windows.Forms.MessageBox.Show(Localizator.Getinstance().GetLocalizedString("ThisActionHasNotBeenRecognized") + elementType); } else { throw new Exception(Localizator.Getinstance().GetLocalizedString("ThisActionHasNotBeenRecognized") + elementType); } break; } return(element); }