예제 #1
0
        static bool ParseV2(EditorModelV4 model)
        {
            var file = model.VideoFolder.GetFiles(LocationsV4.LocalFileNameV2).FirstOrDefault();

            if (file == null)
            {
                return(false);
            }
            var container = new JavaScriptSerializer().Deserialize <FileContainerV2>(File.ReadAllText(file.FullName));

            if (container.Montage != null)
            {
                model.Montage.Chunks      = container.Montage.Chunks;
                model.Montage.Borders     = container.Montage.Borders;
                model.Montage.Information = container.Montage.Information;
                model.Montage.Shift       = container.Montage.Shift;
                model.Montage.TotalLength = container.Montage.TotalLength;
                model.Montage.Intervals   = new List <IntervalV4>();
                if (container.Montage.Intervals != null)
                {
                    foreach (var e in container.Montage.Intervals)
                    {
                        model.Montage.Intervals.Add(new IntervalV4(
                                                        (int)Math.Round(e.StartTime * 1000),
                                                        (int)Math.Round(e.EndTime * 1000),
                                                        e.HasVoice));
                    }
                }
            }
            if (container.WindowState != null)
            {
                model.WindowState = container.WindowState;
            }
            return(true);
        }
예제 #2
0
        public static EditorModelV4 Load(string subdirectory)
        {
            var localDirectory = new DirectoryInfo(subdirectory);

            if (!localDirectory.Exists)
            {
                throw new Exception("Local directory '" + subdirectory + "' is not found");
            }
            var rootDirectory = localDirectory;

            while (true)
            {
                try
                {
                    rootDirectory = rootDirectory.Parent;
                }
                catch
                {
                    throw new Exception("Root directory is not found. Root directory must be a parent of '" + localDirectory.FullName + "' and contain global data file '" + LocationsV4.GlobalFileName + "'");
                }
                if (rootDirectory.GetFiles(LocationsV4.GlobalFileName).Length != 0)
                {
                    break;
                }
            }

            var programFolder = new FileInfo(Assembly.GetExecutingAssembly().FullName).Directory;

            var editorModel = new EditorModelV4 {
                ProgramFolder = programFolder,
                VideoFolder   = localDirectory,
                ChunkFolder   = localDirectory.CreateSubdirectory("chunks"),
                RootFolder    = rootDirectory
            };


            FilesWereNotFound = false;
            if (!ParseV3(editorModel) && !ParseV2(editorModel) && !ParseV1(editorModel))
            {
                FilesWereNotFound   = true;
                editorModel.Montage = new MontageModelV4
                {
                    Shift       = 0,
                    TotalLength = 90 * 60 * 1000     //TODO: как-то по-разумному определить это время
                };
                editorModel.Montage.Chunks.Add(new ChunkDataV4 {
                    StartTime = 0, Length = editorModel.Montage.TotalLength, Mode = Mode.Undefined
                });
            }
            return(editorModel);
        }
예제 #3
0
        static void SaveV2(EditorModelV4 model)
        {
            model.CreateFileChunks();
            var container = new FileContainerV4()
            {
                FileFormat  = "V3",
                Montage     = model.Montage,
                WindowState = model.WindowState
            };

            using (var stream = new StreamWriter(Path.Combine(model.VideoFolder.FullName, LocationsV4.LocalFileName)))
            {
                stream.WriteLine(new JavaScriptSerializer().Serialize(container));
            }
            ExportV0(model.RootFolder, model.VideoFolder, model.Montage);
        }
예제 #4
0
        static bool ParseV3(EditorModelV4 model)
        {
            var file = model.VideoFolder.GetFiles(LocationsV4.LocalFileName).FirstOrDefault();

            if (file == null)
            {
                return(false);
            }
            var container = new JavaScriptSerializer().Deserialize <FileContainerV4>(File.ReadAllText(file.FullName));

            if (container.Montage != null)
            {
                model.Montage = container.Montage;
            }
            if (container.WindowState != null)
            {
                model.WindowState = container.WindowState;
            }
            return(true);
        }
예제 #5
0
파일: ModelIO.cs 프로젝트: IvanSorokin/Tuto
        public static EditorModelV4 Load(string subdirectory)
        {
            var localDirectory = new DirectoryInfo(subdirectory);
            if (!localDirectory.Exists) throw new Exception("Local directory '"+subdirectory+"' is not found");
            var rootDirectory = localDirectory;
            while (true)
            {
                try
                {
                    rootDirectory = rootDirectory.Parent;
                }
                catch
                {
                    throw new Exception("Root directory is not found. Root directory must be a parent of '"+localDirectory.FullName+"' and contain global data file '"+LocationsV4.GlobalFileName+"'");
                }
                if (rootDirectory.GetFiles(LocationsV4.GlobalFileName).Length!=0)
                    break;
            }

            var programFolder = new FileInfo(Assembly.GetExecutingAssembly().FullName).Directory;

            var editorModel = new EditorModelV4 {
                ProgramFolder = programFolder,
                VideoFolder = localDirectory,
                ChunkFolder = localDirectory.CreateSubdirectory("chunks"),
                RootFolder = rootDirectory
            };

            FilesWereNotFound = false;
            if (!ParseV3(editorModel) && !ParseV2(editorModel) && !ParseV1(editorModel))
            {
                FilesWereNotFound = true;
                editorModel.Montage = new MontageModelV4
                    {
                        Shift = 0,
                        TotalLength = 90 * 60 * 1000 //TODO: как-то по-разумному определить это время
                    };
                editorModel.Montage.Chunks.Add(new ChunkDataV4 { StartTime = 0, Length = editorModel.Montage.TotalLength, Mode = Mode.Undefined });
            }
            return editorModel;
        }
예제 #6
0
        static bool ParseV1(EditorModelV4 model)
        {
            var file = model.VideoFolder.GetFiles(LocationsV4.LocalFileNameV1).FirstOrDefault();

            if (file == null)
            {
                return(false);
            }
            var montageModel = new JavaScriptSerializer().Deserialize <MontageModelV1>(File.ReadAllText(file.FullName));

            model.Montage = new MontageModelV4
            {
                Borders     = montageModel.Borders,
                Chunks      = montageModel.Chunks,
                Shift       = montageModel.Shift,
                TotalLength = montageModel.TotalLength,
                Information = montageModel.Information
            };
            model.WindowState = new WindowStateV4
            {
                CurrentMode     = montageModel.EditorMode,
                CurrentPosition = montageModel.CurrentPosition,
            };

            if (model.Montage.Information.Episodes.Count == 0)
            {
                var titles = model.VideoFolder.GetFiles("titles.txt");
                if (titles.Length != 0)
                {
                    var lines = File.ReadAllLines(titles[0].FullName);
                    foreach (var e in lines)
                    {
                        model.Montage.Information.Episodes.Add(new EpisodInfoV4 {
                            Name = e
                        });
                    }
                }
            }
            return(true);
        }
예제 #7
0
파일: ModelIO.cs 프로젝트: IvanSorokin/Tuto
 static void SaveV2(EditorModelV4 model)
 {
     model.CreateFileChunks();
     var container = new FileContainerV4()
     {
         FileFormat = "V3",
         Montage = model.Montage,
         WindowState = model.WindowState
     };
     using (var stream = new StreamWriter(Path.Combine(model.VideoFolder.FullName,LocationsV4.LocalFileName)))
     {
         stream.WriteLine(new JavaScriptSerializer().Serialize(container));
     }
     ExportV0(model.RootFolder, model.VideoFolder, model.Montage);
 }
예제 #8
0
파일: ModelIO.cs 프로젝트: IvanSorokin/Tuto
        static bool ParseV3(EditorModelV4 model)
        {
            var file = model.VideoFolder.GetFiles(LocationsV4.LocalFileName).FirstOrDefault();
            if (file == null) return false;
            var container = new JavaScriptSerializer().Deserialize<FileContainerV4>(File.ReadAllText(file.FullName));

            if (container.Montage!=null)
                model.Montage = container.Montage;
            if (container.WindowState!=null)
                model.WindowState=container.WindowState;
            return true;
        }
예제 #9
0
파일: ModelIO.cs 프로젝트: IvanSorokin/Tuto
        static bool ParseV2(EditorModelV4 model)
        {
            var file = model.VideoFolder.GetFiles(LocationsV4.LocalFileNameV2).FirstOrDefault();
            if (file == null) return false;
            var container = new JavaScriptSerializer().Deserialize<FileContainerV2>(File.ReadAllText(file.FullName));

            if (container.Montage != null)
            {
                model.Montage.Chunks = container.Montage.Chunks;
                model.Montage.Borders = container.Montage.Borders;
                model.Montage.Information = container.Montage.Information;
                model.Montage.Shift = container.Montage.Shift;
                model.Montage.TotalLength = container.Montage.TotalLength;
                model.Montage.Intervals = new List<IntervalV4>();
                if (container.Montage.Intervals!=null)
                foreach (var e in container.Montage.Intervals)
                    model.Montage.Intervals.Add(new IntervalV4(
                        (int)Math.Round(e.StartTime * 1000),
                        (int)Math.Round(e.EndTime * 1000),
                        e.HasVoice));
            }
            if (container.WindowState != null)
                model.WindowState = container.WindowState;
            return true;
        }
예제 #10
0
파일: ModelIO.cs 프로젝트: IvanSorokin/Tuto
        static bool ParseV1(EditorModelV4 model)
        {
            var file = model.VideoFolder.GetFiles(LocationsV4.LocalFileNameV1).FirstOrDefault();
            if (file == null) return false;
            var montageModel=new JavaScriptSerializer().Deserialize<MontageModelV1>(File.ReadAllText(file.FullName));

            model.Montage= new MontageModelV4
                {
                    Borders = montageModel.Borders,
                    Chunks = montageModel.Chunks,
                    Shift = montageModel.Shift,
                    TotalLength = montageModel.TotalLength,
                    Information = montageModel.Information
                };
            model.WindowState= new WindowStateV4
                {
                    CurrentMode = montageModel.EditorMode,
                    CurrentPosition = montageModel.CurrentPosition,
                };

            if (model.Montage.Information.Episodes.Count == 0)
            {
                var titles = model.VideoFolder.GetFiles("titles.txt");
                if (titles.Length != 0)
                {
                    var lines = File.ReadAllLines(titles[0].FullName);
                    foreach (var e in lines)
                        model.Montage.Information.Episodes.Add(new EpisodInfoV4 { Name = e });
                }
            }
            return true;
        }
예제 #11
0
파일: ModelIO.cs 프로젝트: IvanSorokin/Tuto
 public static void Save(EditorModelV4 model)
 {
     SaveV2(model);
 }
예제 #12
0
파일: Locations.cs 프로젝트: jokalee/Tuto
 internal LocationsV4(EditorModelV4 model)
 {
     this.model = model;
 }
예제 #13
0
 public static void Save(EditorModelV4 model)
 {
     SaveV2(model);
 }
예제 #14
0
 internal LocationsV4(EditorModelV4 model)
 {
     this.model = model;
 }