static public bool ImportDialoguesFromCsv(string importPath, List <Package> packages, List <Language> languages, bool importLocalization, bool importWorkstring, bool importInformation) { var project = ResourcesHandler.Project; //Dialogue, Node ID, Timestamp, Voicing ID, Index, Package, SceneType, Context, Voicing, Voicing Intensity, Speaker, Workstring Text, Words, ...Languages..., comments var headerRedirects = new Dictionary <string, string>(); headerRedirects.Add("ID", "Node ID"); headerRedirects.Add("Workstring", "Workstring Text"); if (importPath == String.Empty) { EditorCore.LogError("Import Localization failed : no file specified"); return(false); } if (!File.Exists(importPath)) { EditorCore.LogError("Import Localization failed : file not found"); return(false); } while (Utility.IsFileLocked(importPath)) { EditorCore.LogError("Import Localization failed : file is locked"); var dialogLocked = new DialogLockedFile(importPath); DialogResult eResult = dialogLocked.ShowDialog(); if (eResult == DialogResult.Cancel) { return(false); } } DateTime currentTime = Utility.GetCurrentTime(); using (System.IO.StreamReader file = new System.IO.StreamReader(importPath, Encoding.UTF8)) { ExporterCsv.CsvFileReader reader = new ExporterCsv.CsvFileReader(); if (reader.ParseHeaders(file, headerRedirects)) { while (reader.ParseNextLine()) { Dialogue dialogue = ResourcesHandler.GetDialogue(reader.GetCell("Dialogue")); if (dialogue != null) { if (!packages.Contains(dialogue.Package)) { continue; } int id = TranslationTable.GetNodeIDFromPrefixedString(reader.GetCell("ID")); DialogueNode node = dialogue.GetNodeByID(id); if (node == null) { continue; } if (node is DialogueNodeRoot) { var dialogueNodeRoot = node as DialogueNodeRoot; if (importInformation) { //Import general Dialogue informations dialogue.Package = project.GetPackage(reader.GetCell("Package")); dialogue.SceneType = reader.GetCell("Scene Type"); dialogue.Context = reader.GetCell("Context"); } } else { DateTime timestampLoca = reader.GetCellAsDate("Timestamp"); DateTime timestampWorkstring; if (node is DialogueNodeSentence) { var dialogueNodeSentence = node as DialogueNodeSentence; if (importWorkstring) { //The current workstring is more recent than the modified workstring if (dialogueNodeSentence.LastEditDate > timestampLoca) { //TODO: popup or option to choose what to do here EditorCore.LogWarning(String.Format("{0} {1} - New workstring older than currently registered workstring, but updated anyway", dialogue.GetName(), id), dialogue, node); } dialogueNodeSentence.Sentence = reader.GetCell("Workstring"); dialogueNodeSentence.LastEditDate = currentTime; timestampLoca = currentTime; } if (importInformation) { //Import Sentence informations (Voicing, Context, Speaker..) string context = reader.GetCell("Context"); dialogueNodeSentence.Context = context; string voicing = reader.GetCell("Voicing"); dialogueNodeSentence.Comment = voicing; string voiceIntensity = reader.GetCell("Voice Intensity"); dialogueNodeSentence.VoiceIntensity = voiceIntensity; string speakerID = ResourcesHandler.Project.GetActorID(reader.GetCell("Speaker")); dialogueNodeSentence.SpeakerID = speakerID; } timestampWorkstring = dialogueNodeSentence.LastEditDate; } else { var dialogueNodeReply = node as DialogueNodeReply; if (importWorkstring) { //The current workstring is more recent than the modified workstring if (dialogueNodeReply.LastEditDate > timestampLoca) { //TODO: popup or option to choose what to do here EditorCore.LogWarning(String.Format("{0} {1} - New workstring older than currently registered workstring, but updated anyway", dialogue.GetName(), id), dialogue, node); } dialogueNodeReply.Reply = reader.GetCell("Workstring"); dialogueNodeReply.LastEditDate = currentTime; timestampLoca = currentTime; } timestampWorkstring = dialogueNodeReply.LastEditDate; } if (importLocalization) { foreach (var language in languages) { //TODO: extract this part in a function, to be used from other importers ETranslationResult translationResult = dialogue.Translations.AddOrUpdateNodeEntry( id, language, timestampLoca, reader.GetCell(language.Name + " Text") ); if (translationResult == ETranslationResult.Accepted || translationResult == ETranslationResult.Accepted_IdenticalTimestamp || translationResult == ETranslationResult.Accepted_IdenticalText) { //The current workstring is more recent than the localized entry if (timestampWorkstring > timestampLoca) { EditorCore.LogWarning(String.Format("{0} {1} - [{2}] Translation accepted but based on an outdated workstring, will be re-exported", dialogue.GetName(), id, language.Name), dialogue, node); } else { //EditorCore.LogInfo(String.Format("{0} {1} - Translation accepted", dialogue.GetName(), id), dialogue.GetName(), id); } } if (translationResult == ETranslationResult.Accepted_IdenticalTimestamp) { EditorCore.LogWarning(String.Format("{0} {1} - [{2}] Translation accepted but with an identical timestamp as the previous entry", dialogue.GetName(), id, language.Name), dialogue, node); } else if (translationResult == ETranslationResult.Accepted_IdenticalText) { EditorCore.LogWarning(String.Format("{0} {1} - [{2}] Translation accepted but with an identical text as the previous entry", dialogue.GetName(), id, language.Name), dialogue, node); } else if (translationResult == ETranslationResult.Refused_EmptyText) { EditorCore.LogWarning(String.Format("{0} {1} - [{2}] Translation refused : empty text", dialogue.GetName(), id, language.Name), dialogue, node); } else if (translationResult == ETranslationResult.Refused_Outdated) { EditorCore.LogWarning(String.Format("{0} {1} - [{2}] Translation refused : outdated timestamp", dialogue.GetName(), id, language.Name), dialogue, node); } else if (translationResult == ETranslationResult.Refused_Identical) { //ignored } } } } } ResourcesHandler.SetDirty(dialogue); } ResourcesHandler.SaveAllDirty(); if (EditorCore.MainWindow != null) { EditorCore.MainWindow.RefreshDirtyFlags(); } EditorCore.ProjectExplorer.ResyncAllFiles(); } } return(true); }