2020-11-23 16:51:05 +01:00
|
|
|
|
using Flowframes.OS;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-11-26 20:17:18 +01:00
|
|
|
|
using System.Globalization;
|
2020-11-23 16:51:05 +01:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Flowframes.IO
|
|
|
|
|
{
|
|
|
|
|
internal class Config
|
|
|
|
|
{
|
|
|
|
|
private static string configPath;
|
|
|
|
|
|
|
|
|
|
private static string[] cachedLines;
|
|
|
|
|
|
|
|
|
|
public static void Init()
|
|
|
|
|
{
|
|
|
|
|
configPath = Path.Combine(Paths.GetDataPath(), "config.ini");
|
|
|
|
|
if (!File.Exists(configPath))
|
|
|
|
|
{
|
|
|
|
|
File.Create(configPath).Close();
|
|
|
|
|
}
|
|
|
|
|
Reload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Set(string key, string value)
|
|
|
|
|
{
|
|
|
|
|
string[] lines = File.ReadAllLines(configPath);
|
|
|
|
|
for (int i = 0; i < lines.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (lines[i].Split('|')[0] == key)
|
|
|
|
|
{
|
|
|
|
|
lines[i] = key + "|" + value;
|
|
|
|
|
File.WriteAllLines(configPath, lines);
|
|
|
|
|
cachedLines = lines;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<string> list = lines.ToList();
|
|
|
|
|
list.Add(key + "|" + value);
|
|
|
|
|
File.WriteAllLines(configPath, list.ToArray());
|
|
|
|
|
cachedLines = list.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-27 09:45:06 +01:00
|
|
|
|
public static string Get(string key, Type type = Type.String)
|
2020-11-23 16:51:05 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < cachedLines.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
string[] keyValuePair = cachedLines[i].Split('|');
|
2020-11-26 00:07:45 +01:00
|
|
|
|
if (keyValuePair[0] == key && !string.IsNullOrWhiteSpace(keyValuePair[1]))
|
|
|
|
|
{
|
2020-11-23 16:51:05 +01:00
|
|
|
|
return keyValuePair[1];
|
2020-11-26 00:07:45 +01:00
|
|
|
|
}
|
2020-11-23 16:51:05 +01:00
|
|
|
|
}
|
2020-11-27 09:45:06 +01:00
|
|
|
|
return WriteDefaultValIfExists(key, type);
|
2020-11-23 16:51:05 +01:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log($"Failed to get {key.Wrap()} from config! {e.Message}");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool GetBool(string key)
|
|
|
|
|
{
|
2020-11-27 09:45:06 +01:00
|
|
|
|
return bool.Parse(Get(key, Type.Bool));
|
2020-11-23 16:51:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int GetInt(string key)
|
|
|
|
|
{
|
2020-11-27 09:45:06 +01:00
|
|
|
|
return int.Parse(Get(key, Type.Int));
|
2020-11-23 16:51:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static float GetFloat(string key)
|
|
|
|
|
{
|
2020-11-27 09:45:06 +01:00
|
|
|
|
return float.Parse(Get(key, Type.Float), CultureInfo.InvariantCulture);
|
2020-11-23 16:51:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-06 18:49:53 +01:00
|
|
|
|
public static string GetFloatString (string key)
|
|
|
|
|
{
|
|
|
|
|
return Get(key, Type.Float).Replace(",", ".");
|
|
|
|
|
}
|
2020-11-27 09:45:06 +01:00
|
|
|
|
|
|
|
|
|
public enum Type { String, Int, Float, Bool }
|
2020-12-06 18:49:53 +01:00
|
|
|
|
private static string WriteDefaultValIfExists(string key, Type type)
|
2020-11-23 16:51:05 +01:00
|
|
|
|
{
|
2020-11-27 09:45:06 +01:00
|
|
|
|
if (key == "maxVidHeight") return WriteDefault(key, "2160");
|
|
|
|
|
if (key == "delLogsOnStartup") return WriteDefault(key, "True");
|
|
|
|
|
if (key == "tempDirCustom") return WriteDefault(key, "C:/");
|
2020-11-25 17:27:15 +01:00
|
|
|
|
// Interpolation
|
2020-11-27 09:45:06 +01:00
|
|
|
|
if (key == "dedupMode") return WriteDefault(key, "2");
|
|
|
|
|
if (key == "dedupThresh") return WriteDefault(key, "2");
|
|
|
|
|
if (key == "enableAudio") return WriteDefault(key, "True");
|
2020-12-07 12:34:12 +01:00
|
|
|
|
if (key == "autoDedupFrames") return WriteDefault(key, "100");
|
2020-11-27 09:45:06 +01:00
|
|
|
|
if (key == "vfrDedupe") return WriteDefault(key, "True");
|
|
|
|
|
if (key == "timingMode") return WriteDefault(key, "1");
|
|
|
|
|
if (key == "scnDetectValue") return WriteDefault(key, "0.2");
|
2020-12-06 18:49:53 +01:00
|
|
|
|
if (key == "autoEncMode") return WriteDefault(key, "2");
|
2020-11-25 17:27:15 +01:00
|
|
|
|
// Video Export
|
2020-11-27 09:45:06 +01:00
|
|
|
|
if (key == "h264Crf") return WriteDefault(key, "20");
|
|
|
|
|
if (key == "h265Crf") return WriteDefault(key, "22");
|
|
|
|
|
if (key == "gifskiQ") return WriteDefault(key, "95");
|
|
|
|
|
if (key == "minVidLength") return WriteDefault(key, "2");
|
2020-11-25 17:27:15 +01:00
|
|
|
|
// AI
|
2020-11-27 09:45:06 +01:00
|
|
|
|
if (key == "rifeMode") return WriteDefault(key, ((NvApi.GetVramGb() > 7f) ? 1 : 0).ToString()); // Enable by default if GPU has >7gb VRAM
|
|
|
|
|
if (key == "ncnnThreads") return WriteDefault(key, "1");
|
2020-11-25 17:27:15 +01:00
|
|
|
|
// Debug / Other / Experimental
|
2020-11-27 09:45:06 +01:00
|
|
|
|
if (key == "ffEncPreset") return WriteDefault(key, "medium");
|
2020-11-25 17:27:15 +01:00
|
|
|
|
// Tile Sizes
|
2020-11-27 09:45:06 +01:00
|
|
|
|
if (key == "tilesize_RIFE_NCNN") return WriteDefault(key, "2048");
|
|
|
|
|
if (key == "tilesize_DAIN_NCNN") return WriteDefault(key, "512");
|
|
|
|
|
if (key == "tilesize_CAIN_NCNN") return WriteDefault(key, "2048");
|
|
|
|
|
|
|
|
|
|
if (type == Type.Int || type == Type.Float) return WriteDefault(key, "0"); // Write default int/float (0)
|
|
|
|
|
if (type == Type.Bool) return WriteDefault(key, "False"); // Write default bool (False)
|
2020-11-23 16:51:05 +01:00
|
|
|
|
return WriteDefault(key, "0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string WriteDefault(string key, string def)
|
|
|
|
|
{
|
|
|
|
|
Set(key, def);
|
|
|
|
|
return def;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void Reload()
|
|
|
|
|
{
|
|
|
|
|
cachedLines = File.ReadAllLines(configPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|