public void RollbackChangesFromFolder(List<FileProperties> files, List<string> patch, FileManager fileManager) { string name; List<string> updatedFile; List<string> singlePatch = new List<string>(); for (int i = 0; i < patch.Count; ++i) { // we found new patch and we have to find file to lay it if (patch[i].StartsWith("--- ")) { name = patch[i]; updatedFile = new List<string>(); singlePatch.Add(patch[i]); singlePatch.Add(patch[i + 1]); // Load patch for 1 file for (int j = i + 2; j < patch.Count; ++j) { // check if new patch started if (patch[j].StartsWith("--- ")) { j = j - 1; break; } if (!patch[j].StartsWith("@@ -") && !patch[j].StartsWith("+")) { if (patch[j].StartsWith("-")) { updatedFile.Add(patch[j].Remove(0, 1)); } else { updatedFile.Add(patch[j]); } } singlePatch.Add(patch[j]); } // Apply patch SaveUpdatedFile(files, updatedFile, singlePatch, name, fileManager); // clear patch collection singlePatch.Clear(); updatedFile.Clear(); } } }
private void SaveUpdatedFile(List<FileProperties> files, List<string> updatedFile, List<string> singlePatch, string filePath, FileManager fileManager) { foreach (FileProperties fp in files) { if (fp.AbsolutePath != string.Empty && filePath.Contains(fp.AbsolutePath)) { // We found searching object, and we add updatedFile to it fp.AddUpdatedFile(updatedFile, singlePatch); fileManager.SaveUpdatedFile(updatedFile, fp.FilePath); } else if (fp.children != null) { SaveUpdatedFile(fp.children, updatedFile, singlePatch, filePath, fileManager); } } }