Esempio n. 1
0
        void CheckGUIDCorrectness(IVideothequeLoadingUI ui)
        {
            var problems = EditorModels
                           .SelectMany(model => model.Montage.Information.Episodes.Select(episode => new { model, episode }))
                           .GroupBy(x => x.episode.Guid)
                           .Where(x => x.Count() > 1)
                           .ToList();

            foreach (var p in problems)
            {
                var prompt  = "Duplicating GUID '" + p.Key + "' for episodes in videotheque. Select which episode gets a new guid";
                var options = p
                              .Select(z => new VideothequeLoadingRequestItem {
                    Type   = VideothequeLoadingRequestItemType.NoFile,
                    Prompt = z.model.Montage.DisplayedRawLocation + ", " + z.episode.Name
                })
                              .ToList();
                options.Add(new VideothequeLoadingRequestItem
                {
                    Type   = VideothequeLoadingRequestItemType.NoFile,
                    Prompt = "Don't change anything yet. I will review the episodes and decide later."
                });
                var item  = ui.Request(prompt, options.ToArray());
                var index = options.IndexOf(item);
                if (index == options.Count - 1)
                {
                    continue;
                }
                var pair = p.Skip(index).First();
                pair.episode.Guid = Guid.NewGuid();
                SaveEditorModel(pair.model);
            }
        }
Esempio n. 2
0
 void CreateModels(IVideothequeLoadingUI ui)
 {
     ui.StartPOSTWork("Creating models");
     models = new List <EditorModel>();
     foreach (var e in loadedContainer)
     {
         var hash = e.Item1.MontageModel.RawVideoHash;
         if (hash == null)
         {
             throw new Exception("No reference to video is specified in the model");
         }
         DirectoryInfo rawDirectory = null;
         if (binaryHashes.ContainsKey(hash))
         {
             rawDirectory = binaryHashes[hash];
         }
         var model = LoadExistingModel(e.Item1, e.Item2, rawDirectory);
         binaryHashes.Remove(hash);
         models.Add(model);
     }
     foreach (var e in binaryHashes)
     {
         var model = CreateNewModel(e.Value, e.Key);
         models.Add(model);
     }
     ui.CompletePOSTWork(true);
 }
Esempio n. 3
0
 void LoadBuiltInSoftware(IVideothequeLoadingUI ui)
 {
     //initialize built-in components
     CheckFile(Locations.GNP, ui, "GNP is not found in program's folder. Please reinstall Tuto");
     CheckFile(Locations.NR, ui, "NR is not found in program's folder. Please reinstall Tuto");
     CheckFile(Locations.PraatExecutable, ui, "PRAAT is not found in program's folder. Please reinstall Tuto");
 }
Esempio n. 4
0
        static T Check <T>(
            T path,
            IVideothequeLoadingUI ui,
            Func <T, string> name,
            Func <T, bool> isOk,
            Func <T> requestNew
            )
            where T : class
        {
            while (true)
            {
                if (path != null)
                {
                    ui.StartPOSTWork("Checking " + name(path));
                    bool ok = isOk(path);
                    ui.CompletePOSTWork(ok);
                    if (ok)
                    {
                        return(path);
                    }
                }
                path = requestNew();
                if (path == null)
                {
                    break;
                }
            }

            throw new LoadingException();
        }
Esempio n. 5
0
        void LoadContainers(IVideothequeLoadingUI ui)
        {
            ui.StartPOSTWork("Loading models");
            loadedContainer = new List <Tuple <FileContainer, FileInfo> >();
            LoadFiles <FileContainer>(ModelsFolder, Names.ModelExtension, loadedContainer);

            ui.CompletePOSTWork(true);
        }
Esempio n. 6
0
        void CheckSubdirectories(IVideothequeLoadingUI ui)
        {
            //hooray! videotheque is loaded! Checking Input, Output and other directories

            RawFolder    = CheckVideothequeSubdirectory(Data.PathsSettings.RawPath, Names.DefaultRawFolder, ui, "Can't locate the folder with the raw video files (ones you get from camera)");
            ModelsFolder = CheckVideothequeSubdirectory(Data.PathsSettings.ModelPath, Names.DefaultModelFolder, ui, "Can't locate the folder where the markup (the result of your work) is stored)");
            OutputFolder = CheckVideothequeSubdirectory(Data.PathsSettings.OutputPath, Names.DefaultOutputFolder, ui, "Can't locate the folder with the output video will be stored");
            TempFolder   = CheckVideothequeSubdirectory(Data.PathsSettings.TempPath, Names.DefaultTempFolder, ui, "Can't locate the folder with the temporary files");
            PatchFolder  = CheckVideothequeSubdirectory(Data.PathsSettings.PatchPath, Names.DefaultPatchFolder, ui, "Can't locate the folder with patches");
        }
Esempio n. 7
0
        public static Videotheque Load(string videothequeFileName, IVideothequeLoadingUI ui, bool ignoreExternalSoftware, string customProgramFolder = null)
        {
            ui = new LoadingUIDecorator(ui);
            Videotheque v = new Videotheque();

            if (customProgramFolder == null)
            {
                v.ProgramFolder = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).Directory;
            }
            else
            {
                v.ProgramFolder = new DirectoryInfo(customProgramFolder);
            }
            v.Locations = new VideothequeLocations(v);
            try
            {
                if (!ignoreExternalSoftware)
                {
                    v.LoadBuiltInSoftware(ui);
                    v.LoadExternalReferences(ui);
                    v.SaveStartupFile();
                }
                else
                {
                    v.StartupSettings = new VideothequeStartupSettings();
                }

                v.LoadVideotheque(videothequeFileName, ui);
                var fname = v.VideothequeSettingsFile.FullName;
                if (v.StartupSettings.LastLoadedProjects.Contains(fname))
                {
                    v.StartupSettings.LastLoadedProjects.Remove(fname);
                }
                v.StartupSettings.LastLoadedProjects.Insert(0, fname);
                v.SaveStartupFile();

                v.CheckSubdirectories(ui);
                v.Save();


                v.LoadBinaryHashes(ui);
                v.LoadContainers(ui);
                v.CreateModels(ui);
                v.CheckGUIDCorrectness(ui);


                ui.ExitSuccessfully();
                return(v);
            }
            catch (LoadingException)
            {
                return(null);
            }
        }
Esempio n. 8
0
 DirectoryInfo CheckFolder(DirectoryInfo dir, IVideothequeLoadingUI ui, string prompt, params VideothequeLoadingRequestItem[] requestItems)
 {
     return(Check(dir, ui, d => d.FullName, d => d != null && Directory.Exists(d.FullName),
                  () =>
     {
         var option = ui.Request(prompt, requestItems);
         if (option == null)
         {
             return null;
         }
         return option.InitFolder(option.SuggestedPath);
     }));
 }
Esempio n. 9
0
 static FileInfo CheckFile(FileInfo file, IVideothequeLoadingUI ui, string prompt, params VideothequeLoadingRequestItem[] requestItems)
 {
     return(Check(file, ui, f => f.FullName, f => f != null && File.Exists(f.FullName),
                  () =>
     {
         var option = ui.Request(prompt, requestItems);
         if (option == null)
         {
             return null;
         }
         return option.InitFile(option.SuggestedPath);
     }));
 }
Esempio n. 10
0
        void LoadVideotheque(string videothequeFileName, IVideothequeLoadingUI ui)
        {
            var options = new List <VideothequeLoadingRequestItem>();

            options.Add(new VideothequeLoadingRequestItem
            {
                Prompt   = "Create new videotheque, and keep all files inside its folder",
                Type     = VideothequeLoadingRequestItemType.SaveFile,
                InitFile = CreateEmptyVideotheque
            });
            options.Add(new VideothequeLoadingRequestItem
            {
                Prompt   = "Create new videotheque, and use it with external folders with data (data will be located later)",
                Type     = VideothequeLoadingRequestItemType.SaveFile,
                InitFile = CreateVideothequeForSetup
            });
            options.Add(new VideothequeLoadingRequestItem
            {
                Prompt = "Load existing videotheque",
                Type   = VideothequeLoadingRequestItemType.OpenFile,
            });

            options.AddRange(StartupSettings.LastLoadedProjects.Where(z => File.Exists(z)).Take(3).Select(z => new VideothequeLoadingRequestItem
            {
                Prompt        = "Load videotheque " + z,
                Type          = VideothequeLoadingRequestItemType.NoFile,
                SuggestedPath = z
            }));

            FileInfo vfinfo = null;

            if (videothequeFileName != null)
            {
                vfinfo = new FileInfo(videothequeFileName);
            }
            vfinfo = CheckFile(vfinfo, ui,
                               "Don't see videotheque",
                               options.ToArray()
                               );

            VideothequeSettingsFile = vfinfo;
            Data = HeadedJsonFormat.Read <VideothequeData>(VideothequeSettingsFile);
            if (Data.EditorSettings == null)
            {
                Data.EditorSettings = new VideothequeEditorSettings();
            }
            if (Data.OutputSettings == null)
            {
                Data.OutputSettings = new OutputSettings();
            }
        }
Esempio n. 11
0
        void LoadExternalReferences(IVideothequeLoadingUI ui)
        {
            //loading startup settings
            CheckFile(Locations.StartupSettings, ui,
                      "Startup settings are not found. It is probably the first time you start Tuto. ",
                      new VideothequeLoadingRequestItem
            {
                Prompt        = "Create default startup settings. Be ready to locate external software",
                SuggestedPath = Locations.StartupSettings.FullName,
                Type          = VideothequeLoadingRequestItemType.NoFile,
                InitFile      = CreateDefaultStartup
            });

            StartupSettings = HeadedJsonFormat.Read <VideothequeStartupSettings>(Locations.StartupSettings);
            FileInfo file;

            file = CheckFile(Locations.FFmpegExecutable, ui,
                             "FFMPEG is a free software that processes videofiles. You have to install x64 version of it from http://ffmpeg.zeranoe.com/builds/ prior to using Tuto.",
                             new VideothequeLoadingRequestItem
            {
                Prompt            = "FFMPEG is installed. I'm ready to locate ffmpeg.exe",
                Type              = VideothequeLoadingRequestItemType.OpenFile,
                RequestedFileName = "ffmpeg.exe",
            }
                             );
            StartupSettings.FFMPEGPath = file.FullName;

            file = CheckFile(Locations.SoxExecutable, ui,
                             "SOX is a free software that processes audiofiles. You have to install it from http://sox.sourceforge.net/ prior to using Tuto.",
                             new VideothequeLoadingRequestItem
            {
                Prompt            = "SOX is installed. I'm ready to locate sox.exe",
                Type              = VideothequeLoadingRequestItemType.OpenFile,
                RequestedFileName = "sox.exe",
            }
                             );
            StartupSettings.SoxPath = file.FullName;

            var directory = CheckFolder(Locations.AviSynth, ui,
                                        "AviSynth is a free software that enables scripting of videofiles. You have to install it from http://avisynth.nl/index.php/AviSynth+#Development_branch , version greater than r1800, prior to using Tuto.",
                                        new VideothequeLoadingRequestItem
            {
                Prompt = "AviSynth is installed. I'm ready to locate its folder",
                Type   = VideothequeLoadingRequestItemType.Directory,
            }
                                        );

            StartupSettings.AviSynthPath = directory.FullName;
        }
Esempio n. 12
0
        void LoadBinaryHashes(IVideothequeLoadingUI ui)
        {
            ui.StartPOSTWork("Indexing videofiles in " + RawFolder.FullName);
            var hashes = new RawFileHashes <DirectoryInfo>();

            ComputeHashesInRawSubdirectories(RawFolder, Names.FaceFileName, Names.HashFileName, false, hashes);
            if (hashes.DuplicatedHashes.Count != 0)
            {
                var message = "Some input video files are duplicated. This is not acceptable. Please resolve the issue. The duplications are:\r\n";
                foreach (var e in hashes.DuplicatedHashes)
                {
                    message += e.Value.Select(z => z.FullName).Select(z => MyPath.RelativeTo(z, RawFolder.FullName)).Aggregate((a, b) => a + ", " + b) + "\r\n";
                }
                ui.Request(message, new VideothequeLoadingRequestItem[0]);
                throw new LoadingException();
            }
            binaryHashes = hashes.Hashes;
            ui.CompletePOSTWork(true);
        }
Esempio n. 13
0
 public LoadingUIDecorator(IVideothequeLoadingUI ui)
 {
     innerUI = ui;
 }
Esempio n. 14
0
        DirectoryInfo CheckVideothequeSubdirectory(string relativeLocation, string defaultName, IVideothequeLoadingUI ui, string prompt)
        {
            DirectoryInfo dir = null;

            if (relativeLocation != null)
            {
                if (Path.IsPathRooted(relativeLocation))
                {
                    dir = new DirectoryInfo(relativeLocation);
                }
                dir = new DirectoryInfo(Path.Combine(VideothequeSettingsFile.Directory.FullName, relativeLocation));
            }
            return(CheckFolder(dir, ui, prompt,
                               new VideothequeLoadingRequestItem
            {
                Prompt = "Locate the folder",
                Type = VideothequeLoadingRequestItemType.Directory
            },
                               new VideothequeLoadingRequestItem
            {
                Prompt = "Create an empty folder at the default location",
                Type = VideothequeLoadingRequestItemType.NoFile,
                SuggestedPath = Path.Combine(VideothequeSettingsFile.Directory.FullName, defaultName),
                InitFolder = s => { if (s == null)
                                    {
                                        return null;
                                    }
                                    Directory.CreateDirectory(s); return new DirectoryInfo(s); }
            }

                               ));
        }