mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-23 19:59:31 +01:00
string -> Fraction parsing now has error handling avoiding some problems
This commit is contained in:
@@ -50,9 +50,27 @@ namespace Flowframes.Data
|
|||||||
|
|
||||||
public Fraction(string text)
|
public Fraction(string text)
|
||||||
{
|
{
|
||||||
string[] numbers = text.Split('/');
|
try
|
||||||
Numerator = numbers[0].GetInt();
|
{
|
||||||
Denominator = numbers[1].GetInt();
|
string[] numbers = text.Split('/');
|
||||||
|
Numerator = numbers[0].GetInt();
|
||||||
|
Denominator = numbers[1].GetInt();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Numerator = text.GetFloat().RoundToInt();
|
||||||
|
Denominator = 1;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Numerator = 0;
|
||||||
|
Denominator = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.Log($"Fraction from String: Fraction(\"{text}\") => {Numerator}/{Denominator}", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getGCD(int a, int b)
|
private static int getGCD(int a, int b)
|
||||||
|
|||||||
@@ -96,37 +96,45 @@ namespace Flowframes.Main
|
|||||||
|
|
||||||
public static bool InputIsValid(string inDir, string outDir, Fraction fpsOut, float factor, I.OutMode outMode)
|
public static bool InputIsValid(string inDir, string outDir, Fraction fpsOut, float factor, I.OutMode outMode)
|
||||||
{
|
{
|
||||||
bool passes = true;
|
try
|
||||||
|
|
||||||
bool isFile = !IOUtils.IsPathDirectory(inDir);
|
|
||||||
|
|
||||||
if ((passes && isFile && !IOUtils.IsFileValid(inDir)) || (!isFile && !IOUtils.IsDirValid(inDir)))
|
|
||||||
{
|
{
|
||||||
ShowMessage("Input path is not valid!");
|
bool passes = true;
|
||||||
passes = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (passes && !IOUtils.IsDirValid(outDir))
|
bool isFile = !IOUtils.IsPathDirectory(inDir);
|
||||||
|
|
||||||
|
if ((passes && isFile && !IOUtils.IsFileValid(inDir)) || (!isFile && !IOUtils.IsDirValid(inDir)))
|
||||||
|
{
|
||||||
|
ShowMessage("Input path is not valid!");
|
||||||
|
passes = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (passes && !IOUtils.IsDirValid(outDir))
|
||||||
|
{
|
||||||
|
ShowMessage("Output path is not valid!");
|
||||||
|
passes = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (passes && fpsOut.GetFloat() < 1f || fpsOut.GetFloat() > 1000f)
|
||||||
|
{
|
||||||
|
ShowMessage($"Invalid output frame rate ({fpsOut.GetFloat()}).\nMust be 1-1000.");
|
||||||
|
passes = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Fraction fpsLimit = new Fraction(Config.Get(Config.Key.maxFps));
|
||||||
|
|
||||||
|
if (outMode == I.OutMode.VidGif && fpsOut.GetFloat() > 50 && !(fpsLimit.GetFloat() > 0 && fpsLimit.GetFloat() <= 50))
|
||||||
|
Logger.Log($"Warning: GIF will be encoded at 50 FPS instead of {fpsOut.GetFloat()} as the format doesn't support frame rates that high.");
|
||||||
|
|
||||||
|
if (!passes)
|
||||||
|
I.Cancel("Invalid settings detected.", true);
|
||||||
|
|
||||||
|
return passes;
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
ShowMessage("Output path is not valid!");
|
Logger.Log($"Failed to run InputIsValid: {e.Message}\n{e.StackTrace}", true);
|
||||||
passes = false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (passes && fpsOut.GetFloat() < 1f || fpsOut.GetFloat() > 1000f)
|
|
||||||
{
|
|
||||||
ShowMessage($"Invalid output frame rate ({fpsOut.GetFloat()}).\nMust be 1-1000.");
|
|
||||||
passes = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Fraction fpsLimit = new Fraction(Config.Get(Config.Key.maxFps));
|
|
||||||
|
|
||||||
if (outMode == I.OutMode.VidGif && fpsOut.GetFloat() > 50 && !(fpsLimit.GetFloat() > 0 && fpsLimit.GetFloat() <= 50))
|
|
||||||
Logger.Log($"Warning: GIF will be encoded at 50 FPS instead of {fpsOut.GetFloat()} as the format doesn't support frame rates that high.");
|
|
||||||
|
|
||||||
if (!passes)
|
|
||||||
I.Cancel("Invalid settings detected.", true);
|
|
||||||
|
|
||||||
return passes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool CheckAiAvailable(AI ai)
|
public static bool CheckAiAvailable(AI ai)
|
||||||
|
|||||||
Reference in New Issue
Block a user