diff --git a/Code/AudioVideo/FFmpegUtils.cs b/Code/AudioVideo/FFmpegUtils.cs index 358eb08..838ab5e 100644 --- a/Code/AudioVideo/FFmpegUtils.cs +++ b/Code/AudioVideo/FFmpegUtils.cs @@ -63,7 +63,8 @@ namespace Flowframes.AudioVideo { int crf = Config.GetInt("vp9Crf"); string qualityStr = (crf > 0) ? $"-crf {crf}" : "-lossless 1"; - args += $"{qualityStr} -cpu-used 3 -tile-columns 2 -tile-rows 2 -row-mt 1"; + string cpuUsed = Config.GetInt("vp9Speed", 3).ToString(); + args += $"{qualityStr} -cpu-used {cpuUsed} -tile-columns 2 -tile-rows 2 -row-mt 1"; } if(codec == Codec.ProRes) diff --git a/Code/IO/Config.cs b/Code/IO/Config.cs index 0a6a559..efde548 100644 --- a/Code/IO/Config.cs +++ b/Code/IO/Config.cs @@ -17,16 +17,23 @@ namespace Flowframes.IO public static void Init() { configPath = Path.Combine(Paths.GetDataPath(), "config.ini"); - if (!File.Exists(configPath)) - { - File.Create(configPath).Close(); - } + IOUtils.CreateFileIfNotExists(configPath); Reload(); } public static void Set(string key, string value) { - string[] lines = File.ReadAllLines(configPath); + string[] lines = new string[1]; + try + { + lines = File.ReadAllLines(configPath); + } + catch + { + MessageBox.Show("Failed to read config file!\nFlowframes will try to re-create the file if it does not exist.", "Error"); + if(!File.Exists(configPath)) + Init(); + } for (int i = 0; i < lines.Length; i++) { if (lines[i].Split('|')[0] == key) @@ -39,6 +46,7 @@ namespace Flowframes.IO } List list = lines.ToList(); list.Add(key + "|" + value); + list = list.OrderBy(p => p).ToList(); File.WriteAllLines(configPath, list.ToArray()); cachedLines = list.ToArray(); } diff --git a/Code/IO/IOUtils.cs b/Code/IO/IOUtils.cs index 2313c6d..0ce8461 100644 --- a/Code/IO/IOUtils.cs +++ b/Code/IO/IOUtils.cs @@ -617,5 +617,22 @@ namespace Flowframes.IO DirectoryInfo dir = new DirectoryInfo(path); return dir.GetFiles(pattern, opt).OrderBy(x => x.Name).ToArray(); } + + public static bool CreateFileIfNotExists (string path) + { + if (File.Exists(path)) + return false; + + try + { + File.Create(path).Close(); + return true; + } + catch (Exception e) + { + Logger.Log($"Failed to create file at '{path}': {e.Message}"); + return false; + } + } } }