internal static LocalizationFile MakeNew(DirectoryInfo directory, Func <string, Id <FileInProject>, ISerializer <LocalizerData> > serializer, Func <FileInfo, bool> pathOk, UpToDateFile.BackEnd backend, DirectoryInfo origin) { //Create a stream under an available filename FileInfo path = null; for (int i = 0; path == null; i++) { path = new FileInfo(directory.FullName + Path.DirectorySeparatorChar + "New Localization " + i + ".loc"); if (!pathOk(path)) { path = null; } } LocalizerData data = new LocalizerData(); using (var file = Util.LoadFileStream(path, FileMode.CreateNew, FileAccess.Write)) { } using (var mem = new MemoryStream()) { var id = Id <FileInProject> .New(); LocalizationFile result = new LocalizationFile(id, mem, DocumentPath.FromPath(path, origin), data, serializer(path.FullName, id), backend); //Make a new localization file for an existing project result.File.Writable.Save(); return(result); } }
public void OnElementMoved(Id <FileInProject> id, Changed <FileInfo> change) { m_filePaths[id] = DocumentPath.FromPath(change.To, Origin); if (change.From.FullName != change.To.FullName) { GotChanged(); } }
public void ImportInto(string[] fileNames, DirectoryInfo origin) { var localizations = fileNames.Select(path => new { Path = path, Localization = Load(DocumentPath.FromPath(path, origin), Id <FileInProject> .New(), null, m_backend) }); string message = ""; var keys = m_data.AllLocalizations.Select(kvp => kvp.Key); foreach (var localization in localizations) { foreach (var key in localization.Localization.ExistingLocalizations) { if (keys.Contains(key)) { message += "Trying to import localization for " + key.Serialized() + " from " + localization.Path + " which already exists in the destination\n"; } } } Dictionary <Id <LocalizedText>, string> paths = new Dictionary <Id <LocalizedText>, string>(); foreach (var loc in localizations) { foreach (var key in loc.Localization.ExistingLocalizations) { if (paths.ContainsKey(key)) { message += "Trying to import localization for " + key.Serialized() + " from " + loc.Path + " and from " + paths[key] + "\n"; } else { paths[key] = loc.Path; } } } if (!string.IsNullOrEmpty(message)) { MessageBox.Show(message); } else { foreach (var loc in localizations) { foreach (var key in loc.Localization.ExistingLocalizations) { SetLocalizationAction(key, loc.Localization.Localize(key)).Redo(); } } } }
public Project.TData Read(Stream projectFile) { projectFile.Position = 0; XDocument doc = XDocument.Load(projectFile); var root = doc.Root; string encounteredVersion = root.Attribute("xmlversion").Value; if (encounteredVersion != "1.1") { throw new DeserializerVersionMismatchException("1.1", encounteredVersion); } var conversations = root.Elements("Conversation"); IEnumerable <Project.TData.FileIdAndPath> conversationPaths = conversations.Select(n => new Project.TData.FileIdAndPath((Id <FileInProject> .Parse(n.Attribute("guid").Value)), DocumentPath.FromPath(n.Attribute("path").Value, m_origin))); var localizers = root.Elements("Localization"); IEnumerable <Project.TData.FileIdAndPath> localizerPaths = localizers.Select(n => new Project.TData.FileIdAndPath((Id <FileInProject> .Parse(n.Attribute("guid").Value)), DocumentPath.FromPath(n.Attribute("path").Value, m_origin))); var domains = root.Elements("Domain"); IEnumerable <Project.TData.FileIdAndPath> domainPaths = domains.Select(n => new Project.TData.FileIdAndPath((Id <FileInProject> .Parse(n.Attribute("guid").Value)), DocumentPath.FromPath(n.Attribute("path").Value, m_origin))); var audios = root.Elements("Audio"); IEnumerable <Project.TData.FileIdAndPath> audioPaths = audios.Select(n => new Project.TData.FileIdAndPath((Id <FileInProject> .Parse(n.Attribute("guid").Value)), DocumentPath.FromPath(n.Attribute("path").Value, m_origin))); var localizationSets = root.Elements("LocalizationSet"); List <Project.TData.LocalizerSetData> localizationMappings = new List <Project.TData.LocalizerSetData>(); foreach (var set in localizationSets) { string name = set.Attribute("name").Value; Id <Project.TData.LocalizerSetData> id = Id <Project.TData.LocalizerSetData> .Parse(set.Attribute("guid").Value); IReadOnlyDictionary <Id <LocalizedStringType>, Id <FileInProject> > sources = set.Elements("Source").ToDictionary(e => Id <LocalizedStringType> .Parse(e.Attribute("type").Value), e => Id <FileInProject> .Parse(e.Attribute("file").Value)); localizationMappings.Add(new Project.TData.LocalizerSetData(id, name, sources)); } return(new Project.TData(conversationPaths, domainPaths, localizerPaths, audioPaths, localizationMappings)); }
public static ConversationFile CreateEmpty(DirectoryInfo directory, Project project, INodeFactory nodeFactory, GenerateAudio generateAudio, Func <IDynamicEnumParameter, object, DynamicEnumParameter.Source> getDocumentSource, IAudioLibrary audioProvider, UpToDateFile.BackEnd backEnd, DirectoryInfo origin) { var file = GetAvailableConversationPath(directory, project.Elements); var nodes = Enumerable.Empty <GraphAndUI <NodeUIData> >(); var groups = new List <NodeGroup>(); //Fill the stream with the essential content using (MemoryStream m = new MemoryStream()) { using (FileStream stream = Util.LoadFileStream(file, FileMode.CreateNew, FileAccess.Write)) { project.ConversationSerializer.Write(SerializationUtils.MakeConversationData(nodes, new ConversationEditorData(groups)), m); m.Position = 0; m.CopyTo(stream); } var result = new ConversationFile(Id <FileInProject> .New(), nodes, groups, m, DocumentPath.FromPath(file, origin), project.ConversationSerializer, new ReadOnlyCollection <LoadError>(new LoadError[0]), nodeFactory, generateAudio, getDocumentSource, audioProvider, backEnd); result.m_file.Save(); //Make sure the file starts life as a valid xml document return(result); } }
public static DomainFile CreateEmpty(DirectoryInfo directory, DomainDomain datasource, ISerializer <TData> serializer, Func <FileInfo, bool> pathOk, INodeFactory nodeFactory, Func <IDomainUsage <ConversationNode, TransitionNoduleUIInfo> > domainUsage, Func <IDynamicEnumParameter, object, DynamicEnumParameter.Source> getDocumentSource, UpToDateFile.BackEnd backEnd, DirectoryInfo origin) { //Create a stream under an available filename FileInfo path = null; for (int i = 0; path == null; i++) { path = new FileInfo(directory.FullName + Path.DirectorySeparatorChar + "New Domain " + i + ".dom"); if (!pathOk(path)) { path = null; } } using (MemoryStream m = new MemoryStream()) { using (var stream = Util.LoadFileStream(path, FileMode.CreateNew, FileAccess.Write)) { serializer.Write(SerializationUtils.MakeDomainData(Enumerable.Empty <ConversationNode>(), new ConversationEditorData()), m); m.CopyTo(stream); } var result = new DomainFile(new List <GraphAndUI <NodeUIData> >(), new List <NodeGroup>(), m, Id <FileInProject> .New(), DocumentPath.FromPath(path, origin), new ReadOnlyCollection <LoadError>(new LoadError[0]), datasource, serializer, nodeFactory, domainUsage, getDocumentSource, new List <IAutoCompletePattern>(), backEnd); result.m_file.Save(); //Make sure the file starts life as a valid xml document return(result); } }