예제 #1
0
        // 为所有输入文件生成vs脚本,并添加任务至TaskManager。
        private void WizardFinish(object sender, RoutedEventArgs e)
        {
            string[] inputTemplate = Constants.inputRegex.Split(vsScript);

            // 处理MEMORY标签
            if (Constants.memoryRegex.IsMatch(vsScript))
            {
                string[] memoryTag = Constants.memoryRegex.Split(inputTemplate[0]);
                inputTemplate[0] = memoryTag[0] + memoryTag[1] + eachFreeMemory.ToString() + memoryTag[3];
            }

            // 处理DEBUG标签
            if (Constants.debugRegex.IsMatch(vsScript))
            {
                string[] debugTag = Constants.debugRegex.Split(inputTemplate[3]);
                if (debugTag.Length < 4)
                {
                    // error
                    System.Windows.MessageBox.Show("Debug标签语法错误!", "新建任务向导", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                inputTemplate[3] = debugTag[0] + debugTag[1] + "None" + debugTag[3];
            }


            // 新建任务
            // 1、清理残留文件
            // 2、新建脚本文件
            // 3、新建任务参数
            Cleaner cleaner = new Cleaner();

            foreach (string inputFile in wizardInfo.InputFile)
            {
                List <TaskDetail> existing = workerManager.tm.GetTasksByInputFile(inputFile);
                bool skip = existing.Any(i => i.Progress == TaskStatus.TaskProgress.RUNNING || i.Progress == TaskStatus.TaskProgress.WAITING);

                if (skip)
                {
                    System.Windows.MessageBox.Show($"{inputFile}已经在任务列表里,将跳过处理。", $"{inputFile}已经在任务列表里", MessageBoxButton.OK, MessageBoxImage.Error);
                    continue;
                }

                // 清理文件
                cleaner.Clean(inputFile, new List <string> {
                    json.InputScript, inputFile + ".lwi"
                });

                EpisodeConfig config  = null;
                string        cfgPath = inputFile + ".json";
                FileInfo      cfgFile = new FileInfo(cfgPath);
                if (cfgFile.Exists)
                {
                    try
                    {
                        string configStr = File.ReadAllText(cfgPath);
                        config = JsonConvert.DeserializeObject <EpisodeConfig>(configStr);
                    }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show(ex.ToString(), cfgFile.Name + "文件写错了诶", MessageBoxButton.OK, MessageBoxImage.Error);
                        continue;
                    }
                }

                // 新建vpy文件(inputname.m2ts-mmddHHMM.vpy)
                string vpy = inputTemplate[0] + inputTemplate[1] + "r\"" +
                             inputFile + "\"" + inputTemplate[3];

                DateTime time     = DateTime.Now;
                string   fileName = inputFile + "-" + time.ToString("MMddHHmm") + ".vpy";
                File.WriteAllText(fileName, vpy);

                FileInfo   finfo = new FileInfo(inputFile);
                TaskDetail td    = new TaskDetail
                {
                    TaskName  = string.IsNullOrEmpty(json.ProjectName) ? finfo.Name : json.ProjectName + "-" + finfo.Name,
                    Taskfile  = json.Clone() as TaskProfile,
                    InputFile = inputFile,
                };

                // 更新输入脚本和输出文件拓展名
                td.Taskfile.InputScript = fileName;
                if (config != null)
                {
                    td.Taskfile.Config = config.Clone() as EpisodeConfig;
                }
                td.UpdateOutputFileName();

                // 寻找章节
                td.ChapterStatus = ChapterService.UpdateChapterStatus(td);
                workerManager.AddTask(td);
            }
        }
예제 #2
0
        // 为所有输入文件生成vs脚本,并添加任务至TaskManager。
        private void WizardFinish(object sender, RoutedEventArgs e)
        {
            // 处理PROJECTDIR标签
            if (Constants.projectDirRegex.IsMatch(vsScript))
            {
                string[] dirTag     = Constants.projectDirRegex.Split(vsScript);
                string   projectDir = new DirectoryInfo(wizardInfo.ProjectFile).Parent.FullName;
                vsScript = dirTag[0] + dirTag[1] + "r\"" + projectDir + "\"" + dirTag[3];
            }

            string updatedVsScript = vsScript;

            // 处理MEMORY标签
            if (Constants.memoryRegex.IsMatch(updatedVsScript))
            {
                string[] memoryTag = Constants.memoryRegex.Split(updatedVsScript);
                updatedVsScript = memoryTag[0] + memoryTag[1] + eachFreeMemory.ToString() + memoryTag[3];
            }

            // 处理DEBUG标签
            if (Constants.debugRegex.IsMatch(updatedVsScript))
            {
                string[] debugTag = Constants.debugRegex.Split(updatedVsScript);
                if (debugTag.Length < 4)
                {
                    // error
                    System.Windows.MessageBox.Show("Debug标签语法错误!", "新建任务向导", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                updatedVsScript = debugTag[0] + debugTag[1] + "None" + debugTag[3];
            }

            string[] inputTemplate = Constants.inputRegex.Split(updatedVsScript);

            // 新建任务
            // 1、清理残留文件
            // 2、新建脚本文件
            // 3、新建任务参数
            Cleaner cleaner = new Cleaner();

            foreach (string inputFile in wizardInfo.InputFile)
            {
                List <TaskDetail> existing = workerManager.tm.GetTasksByInputFile(inputFile);
                bool skip = existing.Any(i => i.Progress == TaskStatus.TaskProgress.RUNNING || i.Progress == TaskStatus.TaskProgress.WAITING);

                if (skip)
                {
                    System.Windows.MessageBox.Show($"{inputFile}已经在任务列表里,将跳过处理。", $"{inputFile}已经在任务列表里", MessageBoxButton.OK, MessageBoxImage.Error);
                    continue;
                }

                // 清理文件
                cleaner.Clean(inputFile, new List <string> {
                    json.InputScript, inputFile + ".lwi"
                });

                EpisodeConfig config  = null;
                string        cfgPath = inputFile + ".json";
                FileInfo      cfgFile = new FileInfo(cfgPath);
                if (cfgFile.Exists)
                {
                    try
                    {
                        string configStr = File.ReadAllText(cfgPath);
                        config = JsonConvert.DeserializeObject <EpisodeConfig>(configStr);
                    }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show(ex.ToString(), cfgFile.Name + "文件写错了诶", MessageBoxButton.OK, MessageBoxImage.Error);
                        continue;
                    }
                }

                // 新建vpy文件(inputname.m2ts-mmddHHMM.vpy)
                string vpy = inputTemplate[0] + inputTemplate[1] + "r\"" +
                             inputFile + "\"" + inputTemplate[3];

                string       inputSuffixPath           = inputFile.Replace(':', '_');
                const string stripCommonPathComponents = "BDBOX/BDROM/BD/BDMV/STREAM/BD_VIDEO"; // FIXME: do not hardcode this.
                string[]     strippedComponents        = stripCommonPathComponents.Split(new char[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var comp in strippedComponents)
                {
                    inputSuffixPath = Regex.Replace(inputSuffixPath, @"[/\\]" + Regex.Escape(comp) + @"[/\\]", "\\");
                }
                Logger.Debug("Transformed input path: " + inputSuffixPath);
                string newPath = new DirectoryInfo(wizardInfo.ProjectFile).Parent.FullName + "/" + inputSuffixPath;
                Directory.CreateDirectory(new DirectoryInfo(newPath).Parent.FullName);
                string outPath = Regex.Replace(newPath, @"[/\\]._[/\\]", "\\output\\");
                Directory.CreateDirectory(new DirectoryInfo(outPath).Parent.FullName);

                DateTime time     = DateTime.Now;
                string   fileName = newPath + "-" + time.ToString("MMddHHmm") + ".vpy";
                File.WriteAllText(fileName, vpy);

                FileInfo   finfo = new FileInfo(inputFile);
                TaskDetail td    = new TaskDetail
                {
                    TaskName  = string.IsNullOrEmpty(json.ProjectName) ? finfo.Name : json.ProjectName + "-" + finfo.Name,
                    Taskfile  = json.Clone() as TaskProfile,
                    InputFile = inputFile,
                };
                td.Taskfile.WorkingPathPrefix = newPath;
                td.Taskfile.OutputPathPrefix  = outPath;

                // 更新输入脚本和输出文件拓展名
                td.Taskfile.InputScript = fileName;
                if (config != null)
                {
                    td.Taskfile.Config = config.Clone() as EpisodeConfig;
                }
                td.UpdateOutputFileName();

                // 寻找章节
                td.ChapterStatus = ChapterService.UpdateChapterStatus(td);
                workerManager.AddTask(td);
            }
        }