private static void createFileObject(FileInfo file, ref int folderType) { // Create BasicSet file if (folderType == 0) { FileObject fileObject = new FileObject { NameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(file.FullName), Extension = file.Extension, Path = file.FullName, Lines = new List<string>() }; files.Add(fileObject); mainWindow.listView_FileList.Items.Add(fileObject); LoadDataFromBaseFile(fileObject); } // Create AddSet file else { FileObject fileObjectBasic = new FileObject { NameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(file.FullName), Extension = file.Extension, Path = file.FullName }; mainWindow.listView_FileList.Items.Add(fileObjectBasic); LoadDataFromAddFile(fileObjectBasic); } }
public static void LoadDataFromBaseFile(FileObject fileObject) { try { string[] tempLines = File.ReadAllLines(fileObject.Path); // Fill the object with data foreach (string line in tempLines) { fileObject.Lines.Add(line); } } catch (ArgumentNullException e) { // This shouldn't happen ever System.Windows.MessageBox.Show("Something terrible happend. \n" + e + " \n " + e.InnerException + "", "LoadDataFromBaseFile Exception catched", MessageBoxButton.OK); } }
private static void MergeData(string addLine, int endBeIndex, string beIndex, FileObject file) { Boolean matchFound = false; string addBeFilters = addLine.Substring(endBeIndex); // Check for matches for every line except one line comments for (int i = 0; i < file.Lines.Count; i++) { if (addLine.IndexOf('/', 0) != 0 && addLine.IndexOf('/', 1) != 1) { // Get BE index for current line in Additional file int endBaseBeIndex = GetEndBeIndex(file.Lines[i]); // create substring without BE index that will be added to the end of the line if match is found string baseBeIndex = file.Lines[i].Substring(0, endBaseBeIndex); if (Regex.IsMatch(baseBeIndex, beIndex)) { matchFound = true; file.Lines[i] = file.Lines[i] + addBeFilters; break; } } } if (matchFound == false) { // We haven't found match in all lines of file so we add whole line = BE index + BE filters // Can be also the case where you have difference in the starting number of BE index which is fine file.Lines.Add(addLine); } }
public static void LoadDataFromAddFile(FileObject fileObjectBasic) { foreach (FileObject file in files) { // Check for file names match but not for exact match if (Regex.IsMatch(fileObjectBasic.Name, file.NameWithoutExt) && fileObjectBasic.NameWithoutExt != file.NameWithoutExt) { string[] addLines = File.ReadAllLines(fileObjectBasic.Path); foreach (string addLine in addLines) { try { // exclude one line comments if (addLine.IndexOf('/', 0) != 0 && addLine.IndexOf('/', 1) != 1) { int endBeIndex = GetEndBeIndex(addLine); string beIndex = addLine.Substring(0, endBeIndex); MergeData(addLine, endBeIndex, beIndex, file); } } catch(ArgumentOutOfRangeException e) { // not needed, used for skip fault lines //System.Windows.MessageBox.Show("Something terrible happend. \n" + e + " \n " + e.InnerException + "", "LoadDataFromAddFile Exception catched", MessageBoxButton.OK); } } } } }