/// <summary> /// Defines the script case(case of the keywords) /// </summary> /// <param name="fromFilePath"></param> /// <param name="toFilePath"></param> /// <param name="keywordCase"> /// Optional. The case that will be defined for the keywords. /// "D" - Default, /// "L" - Lower Case, /// "U" - Upper Case /// </param> public void DefineScriptCase(string fromFilePath, string toFilePath, string keywordCase = "D") { try { if (File.Exists(fromFilePath)) { var content = ""; var reader = new StreamReader(fromFilePath, Encoding.GetEncoding("iso-8859-8")); var sysIo = new SysIo { Values = Values }; /* While it's not in the end of file */ while (!reader.EndOfStream) { var line = reader.ReadLine(); if (!string.IsNullOrEmpty(line)) { /* It gets the refactored line. It'll basically replace * all the keywords of the line with the keywords of the * xml(if found) and more important: * it'll replace with the case defined in 'keywordCase'. * If the method return null means that something goes wrong, * thus, the loop in lines will break. */ var newContent = DefineKeywordsCase(line, keywordCase); if (!string.IsNullOrEmpty(newContent)) { content += newContent + Environment.NewLine; } else { break; } } else { content += Environment.NewLine; } } reader.Close(); sysIo.WriteToFile(toFilePath, content); } } catch (Exception exception) { var initEx = new ExceptionHandler(); initEx.Values = Values; initEx.Handle(exception, MethodBase.GetCurrentMethod(), true); } }
/// <summary> /// Install all fonts from a directory /// </summary> /// <param name="path">Directory that contains the fonts</param> public void Install(string path) { var general = new General(); var sysIo = new SysIo(); var res = new Resource(); sysIo.Values = Values; general.Values = Values; res.Values = Values; try { Directory.CreateDirectory(new Constants().TempPath); // Copy all fonts to the temp directory sysIo.CopyTo(path, new Constants().TempPath, new Constants().FontPattern); // Extract the embedded executable according to the bits of the process var resourceName = Environment.Is64BitProcess ? "FontReg_x86-64.exe" : "FontReg_x86-32.exe"; // Export with the same resource name var exePath = Path.Combine(new Constants().TempPath, resourceName); var resource = "ERPToolkit.Resources.FontReg" + "." + resourceName; res.ExtractResource(exePath, resource); // Run the exe... var process = new System.Diagnostics.Process(); var startInfo = new ProcessStartInfo { WindowStyle = ProcessWindowStyle.Hidden, FileName = "cmd.exe", Arguments = @" /C " + exePath + @" /copy", WorkingDirectory = general.GetWorkingDirectory(exePath), UseShellExecute = false, Verb = "runas" }; process.StartInfo = startInfo; process.Start(); process.WaitForExit(); process.Close(); } catch (Exception exception) { var initEx = new ExceptionHandler(); initEx.Values = Values; initEx.Handle(exception, MethodBase.GetCurrentMethod(), true); } }
/// <summary> /// Removes the white spaces of a text file /// </summary> /// <param name="fromFilePath">Path to the file</param> /// <param name="toFilePath">Path to the file</param> public void RemoveWhiteSpaceEnd(string fromFilePath, string toFilePath) { try { if (File.Exists(fromFilePath)) { var content = ""; var reader = new StreamReader(fromFilePath, Encoding.GetEncoding("iso-8859-8")); var sysIo = new SysIo { Values = Values }; while (!reader.EndOfStream) { var line = reader.ReadLine(); if (!string.IsNullOrEmpty(line)) { /* Gets the line without the white spaces in the end*/ content += GetRemovedWhiteSpaceEnd(line) + Environment.NewLine; } else { content += Environment.NewLine; } } reader.Close(); sysIo.WriteToFile(toFilePath, content); } } catch (Exception exception) { var initEx = new ExceptionHandler(); initEx.Values = Values; initEx.Handle(exception, MethodBase.GetCurrentMethod(), true); } }
/// <summary> /// Changes a block('sub' or 'function') of a vbscript /// </summary> /// <param name="fromFilePath">Path to the file</param> /// <param name="toFilePath">Path to the file</param> /// <param name="oldBlockName">Name of the old block(block that'll be replaced)</param> /// <param name="newBlock">Entire new block('sub' or 'function')</param> public void ChangeBlock(string fromFilePath, string toFilePath, string oldBlockName, string newBlock) { try { if (File.Exists(fromFilePath)) { var content = ""; var reader = new StreamReader(fromFilePath, Encoding.GetEncoding("iso-8859-8")); var sysIo = new SysIo { Values = Values }; while (!reader.EndOfStream) { var line = reader.ReadLine(); if (!string.IsNullOrEmpty(line)) { if (IsBlock(line)) { /* Checks if the block that we must find to replace * is equal to the block that was found in this line */ if (oldBlockName.ToLower().Trim().Equals(GetBlockName(line).ToLower().Trim())) { /* Reads the lines while it is the old block. Thus, * when have finished the reading, we just update the * the text part that wasn't added yet. */ ReadWhileBlock(reader); /* Gets the new block */ content += newBlock + Environment.NewLine; } else { content += line + Environment.NewLine; } } else { content += line + Environment.NewLine; } } else { content += line + Environment.NewLine; } } reader.Close(); sysIo.WriteToFile(toFilePath, content); } } catch (Exception exception) { var initEx = new ExceptionHandler(); initEx.Values = Values; initEx.Handle(exception, MethodBase.GetCurrentMethod(), true); } }
/// <summary> /// Adds summaries to a corresponding vbscript /// </summary> /// <param name="fromFilePath">Path to the file</param> /// <param name="toFilePath">Path to the file</param> /// <param name="tags">Tags</param> public void AddSummary(string fromFilePath, string toFilePath, string tags) { try { if (File.Exists(fromFilePath)) { var content = ""; /* Check if the last tag has the separator in the end. If not, * the separator will be inserted in the end of the string. We need this * because the last tag is not considered if it hasn't the separator, thus, * if the user does not specify, will be included anyway */ tags = !string.IsNullOrEmpty(tags) && !tags.Substring(tags.Length - 1, 1).Equals(new Constants().DefaultSeparator) ? tags + ";" : tags; var reader = new StreamReader(fromFilePath, Encoding.GetEncoding("iso-8859-8")); var sysIo = new SysIo { Values = Values }; while (!reader.EndOfStream) { var line = reader.ReadLine(); if (!string.IsNullOrEmpty(line)) { /* * Check if it's a block. It means that the line found * is a function or sub. */ if (IsBlock(line)) { /* Gets the parameters */ var parameters = GetParameters(line, reader); /* Checks if there are parameters, if not, * the line cannot break(NewLine) */ if (!string.IsNullOrEmpty(parameters)) { content += GetSummary(parameters) + Environment.NewLine; } else { content += GetSummary(parameters); } /* Gets information TAGs */ content += GetTags(tags) + Environment.NewLine; /* Gets the line and the cumulative string * if it has. */ content += line + Environment.NewLine + _cumulativestring; /* Cleans the commulative string because * we might have other functions * or subs where their parameters are declared in * more than one line */ _cumulativestring = ""; } else { content += line + Environment.NewLine; } } else { content += line + Environment.NewLine; } } /* Closes the object */ reader.Close(); /* Updates or creates a new file containing * the summaries(if the conditions were satisfied) */ sysIo.WriteToFile(toFilePath, content); } } catch (Exception exception) { var initEx = new ExceptionHandler(); initEx.Values = Values; initEx.Handle(exception, MethodBase.GetCurrentMethod(), true); } }