/// <summary> /// Add a tmx file to the language repository /// </summary> /// <param name="tmxFile">Tmx file object</param> /// <returns>Sucessful</returns> public bool Add(TmxFile tmxFile) { // Set modifiers tmxFile.isNew = true; tmxFile.isModified = false; tmxFile.isDeleted = false; tmxFile.Id = Guid.NewGuid(); // Check language is in history foreach (List <TmxFile> files in History) { if (files.First <TmxFile>().LanguageCode == tmxFile.LanguageCode) { // Add files to list in history if (!tmxFile.FileInfo.Directory.Exists) { tmxFile.FileInfo = new FileInfo(Path.Combine(Root.FullName, tmxFile.LanguageCode, tmxFile.FileInfo.Name)); } files.Add(tmxFile); return(true); } } List <TmxFile> repository = Get(tmxFile.LanguageCode); if (repository.Count != 0) { // New list will have been added to history so recall Add return(Add(tmxFile)); } else { // Create new repository folder if (!Directory.Exists(tmxFile.FileInfo.Directory.FullName)) { string path = Path.Combine(Root.FullName, tmxFile.LanguageCode); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } tmxFile.FileInfo = new FileInfo(Path.Combine(path, tmxFile.FileInfo.Name)); } History.Add(new List <TmxFile>() { tmxFile }); return(true); } }
/// <summary> /// Update a tmx file /// </summary> /// <param name="tmxFile">Tmx file to update</param> /// <returns>Sucessful</returns> public bool Update(TmxFile tmxFile) { foreach (List <TmxFile> files in History) { for (int i = 0; i < files.Count; i++) { if (files[i].Id == tmxFile.Id) { // Set modifiers tmxFile.isModified = tmxFile.isDeleted || tmxFile.isNew ? false : true; // Replace file in history files[i] = tmxFile; return(true); } } } return(false); }