示例#1
0
        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);
            }
        }
示例#2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="initialData">Represents the current contents of the file. Reference is not held. A copy is made.</param>
 /// <param name="path"></param>
 /// <param name="data"></param>
 /// <param name="serializer"></param>
 private LocalizationFile(Id <FileInProject> id, MemoryStream initialData, DocumentPath path, LocalizerData data, ISerializer <LocalizerData> serializer, UpToDateFile.BackEnd backend)
 {
     Id        = id;
     m_backend = backend;
     m_file    = new SaveableFileExternalChangedSource(initialData, path.FileInfo, s => { serializer.Write(m_data, s); }, Changed, Saved, backend);
     m_data    = data;
 }