public static void WritePluginHotkeySnippits(plugin plg, bool Overwrite) { if (plg == null) { return; } if (plg.ParentProfile == null) { return; } if (plg.commands == null || plg.commands.Length == 0) { return; } string sSnippitPath = plg.ParentProfile.codeLanguage.paths.PluginFullPath; if (Directory.Exists(sSnippitPath) == false) { Directory.CreateDirectory(sSnippitPath); } Parallel.ForEach(plg.commands, c => { if (c.type != commandType.include) { return; } if (string.IsNullOrEmpty(c.snippit) == true) { return; } if (string.IsNullOrEmpty(c.code) == true) { return; } string sFile = c.snippit.EndsWith(@".ahk", StringComparison.CurrentCultureIgnoreCase) ? c.snippit : c.snippit + @".ahk"; sFile = Path.GetFileName(sFile); // gets the filename regardless if there is a path or not string sFilePath = Path.Combine(sSnippitPath, sFile); if (File.Exists(sFilePath) == true) { if (Overwrite == false) { return; } File.Delete(sFilePath); } using (StreamWriter writer = new StreamWriter(sFilePath, false, Encoding.UTF8)) { writer.Write(c.code); } }); }
/// <summary> /// Deletes Plugin from Disk. Also delete all the plugin supporting files such as snippits. /// </summary> /// <param name="plg">The Plugin to delete</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException">If <see cref="plugin.ParentProfile"/>is null</exception> public static void DeletePlugin(plugin plg) { if (plg == null) { throw new ArgumentNullException(); } if (plg.ParentProfile == null) { throw new ArgumentException(Properties.Resources.ErrorPluginParentNull); } SnippitInstal inst = new SnippitInstal(); inst.profile = plg.ParentProfile; inst.plugin = new plugin[] { plg }; ReadWrite.DeleteInstal(inst, false, true); }
/// <summary> /// Saves Plugin to Disk /// </summary> /// <param name="pf">The Profile the Plugin Belongs to</param> /// <param name="plg">The Plugin to save</param> /// <param name="Overwrite">If True then all supporting Plugins and Snippits will be overwritten</param> public static void SavePlugin(plugin plg, bool Overwrite) { if (plg == null) { return; } if (plg.ParentProfile == null) { return; } if (string.IsNullOrEmpty(plg.File)) { string strPlgFile = Path.Combine(plg.ParentProfile.codeLanguage.paths.MainDataFullPath, plg.name + @".xml"); plg.File = strPlgFile; } if (File.Exists(plg.File)) { // delete all the old plugin file before saving new again SnippitInstal si = new SnippitInstal(); si.profile = plg.ParentProfile; si.plugin = new plugin[] { plg }; si.File = plg.ParentProfile.File; ReadWrite.DeleteInstal(si, false, false); // delete plugin but leave profile and folders in tact } else { var sPath = Path.GetDirectoryName(plg.File); if (Directory.Exists(sPath) == false) { Directory.CreateDirectory(sPath); } } XmlSerializer writer = new XmlSerializer(typeof(plugin)); FileStream file = File.Create(plg.File); writer.Serialize(file, plg); file.Close(); //ReadWrite.WritePluginHotkeySnippits(plg, Overwrite); //ReadWrite.WritePluginIncludeFiles(plg, Overwrite); //ReadWrite.WritePlugHotStringSnippits(plg, Overwrite); }
private void WritePlugin(plugin p) { if (p.hotstrings == null) { return; } try { foreach (var hs in p.hotstrings) { if (hs.enabled == false) { continue; } switch (hs.type) { case hotstringType.Paste: HashBuilder.AppendLine(hs.UniqueName); this.WriteHotstringPaste(hs); break; case hotstringType.Inline: HashBuilder.AppendLine(hs.UniqueName); this.WriteHotstringInline(hs); break; case hotstringType.Code: HashBuilder.AppendLine(hs.UniqueName); this.WriteHotstringCode(hs); break; default: break; } } } catch (Exception) { throw; } }
private void WritePlugin(plugin p) { if (p.dataItems == null) { return; } try { foreach (var item in p.dataItems) { string sFile = Path.Combine(this.DataItemPath, item.dataFileName); if ((item.overwrite == false) && (File.Exists(sFile) == true)) { continue; } if (File.Exists(sFile)) { File.Delete(sFile); } // if there is no file data then jsut contiinue if (string.IsNullOrEmpty(item.dataValue)) { continue; } if (item.encoded == true) { Util.FileSaveFromBase64(sFile, item.dataValue); } else { File.WriteAllText(sFile, item.dataValue.CleanNewLine()); } } } catch (Exception) { throw; } }
/// <summary> /// Reads the Current Profile from the INI file and creates a new /// <see cref="SnippitInstal"/> Populated with the profile and the Plugins of /// the current Profile /// </summary> /// <returns> /// SnippitInstall Populated with Profile and Plugins. If current Profile in the ini is invalid then Null. /// </returns> /// <remarks> /// Each <see cref="plugin"/> has it <see cref="plugin.ParentProfile"/> set to the current <see cref="profile"/> /// </remarks> public static SnippitInstal ReadCurrentInstall() { profile p = ReadCurrentProfile(); if (p == null) { return(null); } SnippitInstal si = new SnippitInstal(); si.profile = p; si.File = p.File; string PluginPath = p.codeLanguage.paths.MainDataFullPath; if (!Directory.Exists(PluginPath)) { return(si); } var files = Directory.GetFiles(PluginPath, "*.xml"); List <plugin> plgs = new List <plugin>(); foreach (string f in files) { try { plugin plg = plugin.FromFile(f); plg.ParentProfile = si.profile; plgs.Add(plg); } catch (Exception) { } } si.plugin = plgs.ToArray(); return(si); }
Do not build and publish this plugin. It is not production ready
_ => LoadDefaultConfig(plugin, rawConfigs),
foreach (var(plugin, currentPlugin) in plugins)
foreach (var(plugin, types) in LoadedTypes)