private void ValidatePlugin() { var result = ValidateXml.ValidatePluginFile(txtFile.Text); txtResult.Clear(); if (result.HasErrors) { foreach (var strError in result.Errors) { txtResult.AppendText(strError + Environment.NewLine); } } else { txtResult.Text = Properties.Resources.ValidatePluginSuccess; } }
/// <summary> /// Creates a new instance of <see cref="root"/> from <paramref name="FileName"/> /// </summary> /// <param name="FileName">The FileName to the xml that represents the profile</param> /// <returns><see cref="root"/> instance</returns> /// <exception cref="System.Exception">If there are Validation errors with the xml</exception> public static plugin FromFile(string FileName) { ValidationResult vResult = ValidateXml.ValidatePluginFile(FileName); if (vResult.HasErrors == true) { var ex = new System.Exception(vResult.ToString()); throw ex; } XmlSerializer serializer = new XmlSerializer(typeof(plugin)); System.IO.StreamReader reader = new System.IO.StreamReader(FileName); var r = (plugin)serializer.Deserialize(reader); reader.Close(); r.File = FileName; return(r); }
/// <summary> /// Deletes all the plugins in the SnipitInstall and the Profile as well if DeleteProfle is true /// </summary> /// <param name="inst">SnippitInstall instance</param> /// <param name="DeleteProfile">If true the profile will also be deleted if all the plugins are deleted for this profile</param> /// <param name="DeleteEmpytFolders">If true then empty folder will be deleted as well</param> public static void DeleteInstal(SnippitInstal inst, bool DeleteProfile, bool DeleteEmpytFolders) { if (inst == null) { return; } if (inst.profile == null) { throw new ArgumentException("Inst.Profile cannot be null"); } // bool hasProfile = inst.profile != null; if (inst.plugin != null) { bool SnipsFolderExist = Directory.Exists(inst.profile.codeLanguage.paths.SnipsFullPath); bool PluginsFolderExist = Directory.Exists(inst.profile.codeLanguage.paths.PluginFullPath); if (Directory.Exists(inst.profile.codeLanguage.paths.PluginFullPath) == true) { string searchP = "*.ahk"; var files = Directory.GetFiles(inst.profile.codeLanguage.paths.PluginFullPath, searchP); Parallel.ForEach(files, f => { File.Delete(f); }); if (DeleteEmpytFolders == true && IsDirectoryEmpty(inst.profile.codeLanguage.paths.PluginFullPath) == true) { Directory.Delete(inst.profile.codeLanguage.paths.PluginFullPath); } } if (Directory.Exists(inst.profile.codeLanguage.paths.PluginIncludeFullPath) == true) { string searchP = "*.ahk"; var files = Directory.GetFiles(inst.profile.codeLanguage.paths.PluginIncludeFullPath, searchP); Parallel.ForEach(files, f => { File.Delete(f); }); if (DeleteEmpytFolders == true && IsDirectoryEmpty(inst.profile.codeLanguage.paths.PluginIncludeFullPath) == true) { Directory.Delete(inst.profile.codeLanguage.paths.PluginIncludeFullPath); } } if (Directory.Exists(inst.profile.codeLanguage.paths.SnippitInlinePath)) { string searchP = "*" + AppCommon.Instance.DefaultSnippitExt; var files = Directory.GetFiles(inst.profile.codeLanguage.paths.SnippitInlinePath, searchP); Parallel.ForEach(files, f => { File.Delete(f); }); if (DeleteEmpytFolders == true && IsDirectoryEmpty(inst.profile.codeLanguage.paths.SnippitInlinePath) == true) { Directory.Delete(inst.profile.codeLanguage.paths.SnippitInlinePath); } } if (inst.plugin != null) { foreach (var plg in inst.plugin) { if (string.IsNullOrEmpty(plg.File) == false && File.Exists(plg.File) == true) { File.Delete(plg.File); } } } //if (Directory.Exists(inst.profile.codeLanguage.paths.MainDataFullPath)) //{ // string searchP = "*.xml"; // var files = Directory.GetFiles(inst.profile.codeLanguage.paths.MainDataFullPath, searchP); // Parallel.ForEach(files, f => { // File.Delete(f); // }); //} if (DeleteEmpytFolders == true && Directory.Exists(inst.profile.codeLanguage.paths.MainDataFullPath)) { if (IsDirectoryEmpty(inst.profile.codeLanguage.paths.MainDataFullPath)) { Directory.Delete(inst.profile.codeLanguage.paths.MainDataFullPath); } } } if (DeleteProfile == true) { // check and see if all the XML file have been removed from the data folder before deleting profile if (Directory.Exists(inst.profile.codeLanguage.paths.MainDataFullPath)) { // if the folder exist we have to test for any valid plugin var files = Directory.GetFiles(inst.profile.codeLanguage.paths.MainDataFullPath, "*.xml"); bool bPluginExist = false; foreach (var file in files) { var vResult = ValidateXml.ValidatePluginFile(file); if (vResult.HasErrors == false) { bPluginExist = true; break; } } if ((bPluginExist == false) && (File.Exists(inst.profile.File))) { File.Delete(inst.profile.File); } } else { if (File.Exists(inst.profile.File)) { File.Delete(inst.profile.File); } } } }