Skip to content

Commit

Permalink
Always use Invariant shortcuts for ToLower/ToUpper
Browse files Browse the repository at this point in the history
  • Loading branch information
n00mkrad committed Sep 3, 2024
1 parent c31c76f commit 9672c31
Show file tree
Hide file tree
Showing 48 changed files with 131 additions and 227 deletions.
2 changes: 1 addition & 1 deletion CodeLegacy/Data/AiInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum AiBackend { Pytorch, Ncnn, Tensorflow, Other }
public string NameLong { get; set; } = "";
public string FriendlyName { get { return $"{NameShort} ({GetFrameworkString(Backend)})"; } }
public string Description { get { return $"{GetImplemString(Backend)} of {NameShort}{(Backend == AiBackend.Pytorch ? " (Nvidia Only!)" : "")}"; } }
public string PkgDir { get { return NameInternal.Replace("_", "-").ToLowerInvariant(); } }
public string PkgDir { get { return NameInternal.Replace("_", "-").Lower(); } }
public enum InterpFactorSupport { Fixed, AnyPowerOfTwo, AnyInteger, AnyFloat }
public InterpFactorSupport FactorSupport { get; set; } = InterpFactorSupport.Fixed;
public int[] SupportedFactors { get; set; } = new int[0];
Expand Down
2 changes: 1 addition & 1 deletion CodeLegacy/Data/InterpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void RefreshAlpha ()
bool gifOutput = outSettings.Encoder == Enums.Encoding.Encoder.Gif;
bool proResAlpha = outSettings.Encoder == Enums.Encoding.Encoder.ProResKs && OutputUtils.AlphaFormats.Contains(outSettings.PixelFormat);
bool outputSupportsAlpha = pngOutput || gifOutput || proResAlpha;
string ext = inputIsFrames ? Path.GetExtension(IoUtils.GetFilesSorted(inPath).First()).ToLowerInvariant() : Path.GetExtension(inPath).ToLowerInvariant();
string ext = inputIsFrames ? Path.GetExtension(IoUtils.GetFilesSorted(inPath).First()).Lower() : Path.GetExtension(inPath).Lower();
alpha = (alphaModel && outputSupportsAlpha && (ext == ".gif" || ext == ".png" || ext == ".apng" || ext == ".mov"));
Logger.Log($"RefreshAlpha: model.supportsAlpha = {alphaModel} - outputSupportsAlpha = {outputSupportsAlpha} - input ext: {ext} => alpha = {alpha}", true);
}
Expand Down
2 changes: 1 addition & 1 deletion CodeLegacy/Data/MediaFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public MediaFile(string path, bool requestFpsInputIfUnset = true)
Name = FileInfo.Name;
SourcePath = FileInfo.FullName;
ImportPath = FileInfo.FullName;
Format = FileInfo.Extension.Remove(".").ToUpper();
Format = FileInfo.Extension.Remove(".").Upper();
InputRate = new Fraction(-1, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion CodeLegacy/Data/SubtitleTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public SubtitleTrack(int streamNum, string metaStr, string encodingStr)
{
streamIndex = streamNum;
lang = metaStr.Trim().Replace("_", ".").Replace(" ", ".");
//langFriendly = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(metaStr.ToLowerInvariant().Trim().Replace("_", ".").Replace(" ", "."));
//langFriendly = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(metaStr.Lower().Trim().Replace("_", ".").Replace(" ", "."));
encoding = encodingStr.Trim();
}
}
Expand Down
2 changes: 1 addition & 1 deletion CodeLegacy/Extensions/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public static bool IsConcatFile(this string filePath)
{
try
{
return Path.GetExtension(filePath)?.ToLowerInvariant() == ".concat";
return Path.GetExtension(filePath)?.Lower() == ".concat";
}
catch
{
Expand Down
8 changes: 4 additions & 4 deletions CodeLegacy/IO/IoUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static Image GetImage(string path, bool allowMagickFallback = true, bool

try
{
string ext = new FileInfo(path).Extension.TrimStart('.').ToUpper();
string ext = new FileInfo(path).Extension.TrimStart('.').Upper();

if (incompatibleExtensions.Contains(ext))
return null;
Expand Down Expand Up @@ -330,7 +330,7 @@ public static async Task ReverseRenaming(Dictionary<string, string> oldNewMap)
public static async Task<Fraction> GetVideoFramerate(string path)
{
string[] preferFfmpegReadoutFormats = new string[] { ".gif", ".png", ".apng", ".webp" };
bool preferFfmpegReadout = preferFfmpegReadoutFormats.Contains(Path.GetExtension(path).ToLowerInvariant());
bool preferFfmpegReadout = preferFfmpegReadoutFormats.Contains(Path.GetExtension(path).Lower());

Fraction fps = new Fraction();

Expand Down Expand Up @@ -612,7 +612,7 @@ public static async Task<string> GetCurrentExportFilename(bool fpsLimit, bool wi
filename = filename.Replace("[NAME]", inName);
filename = filename.Replace("[FULLNAME]", Path.GetFileName(curr.inPath));
filename = filename.Replace("[FACTOR]", curr.interpFactor.ToStringDot());
filename = filename.Replace("[AI]", curr.ai.NameShort.ToUpper());
filename = filename.Replace("[AI]", curr.ai.NameShort.Upper());
filename = filename.Replace("[MODEL]", curr.model.Name.Remove(" "));
filename = filename.Replace("[FPS]", fps.ToStringDot("0.###"));
filename = filename.Replace("[ROUNDFPS]", fps.RoundToInt().ToString());
Expand Down Expand Up @@ -758,7 +758,7 @@ public static string GetHash(string path, Hash hashType, bool log = true)
{
MD5 md5 = MD5.Create();
var hash = md5.ComputeHash(stream);
hashStr = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
hashStr = BitConverter.ToString(hash).Replace("-", "").Lower();
}

if (hashType == Hash.CRC32)
Expand Down
2 changes: 1 addition & 1 deletion CodeLegacy/IO/ModelDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static string GetMdlUrl (string ai, string relPath)
string custServer = Config.Get(Config.Key.customServer);
string server = custServer.Trim().Length > 3 ? custServer : Servers.GetServer().GetUrl();
string baseUrl = $"{server}/flowframes/mdl/";
return Path.Combine(baseUrl, ai.ToLowerInvariant(), relPath);
return Path.Combine(baseUrl, ai.Lower(), relPath);
}

static string GetMdlFileUrl(string ai, string model, string relPath)
Expand Down
2 changes: 1 addition & 1 deletion CodeLegacy/Magick/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static async Task Convert (string dir, MagickFormat format, int quality,
int counter = 0;
foreach (string file in files)
{
if (print) Logger.Log("Converting " + Path.GetFileName(file) + " to " + format.ToString().StripNumbers().ToUpper(), false, true);
if (print) Logger.Log("Converting " + Path.GetFileName(file) + " to " + format.ToString().StripNumbers().Upper(), false, true);
MagickImage img = new MagickImage(file);
img.Format = format;
img.Quality = quality;
Expand Down
8 changes: 4 additions & 4 deletions CodeLegacy/Main/Export.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static async Task ExportImageSequence(string framesPath, bool stepByStep)
{
Program.mainForm.SetStatus("Copying output frames...");
Enums.Encoding.Encoder desiredFormat = I.currentSettings.outSettings.Encoder;
string availableFormat = Path.GetExtension(IoUtils.GetFilesSorted(framesPath, "*.*")[0]).Remove(".").ToUpper();
string availableFormat = Path.GetExtension(IoUtils.GetFilesSorted(framesPath, "*.*")[0]).Remove(".").Upper();
string max = Config.Get(Config.Key.maxFps);
Fraction maxFps = max.Contains("/") ? new Fraction(max) : new Fraction(max.GetFloat());
bool fpsLimit = maxFps.GetFloat() > 0f && I.currentSettings.outFps.GetFloat() > maxFps.GetFloat();
Expand All @@ -139,7 +139,7 @@ static async Task ExportImageSequence(string framesPath, bool stepByStep)
IoUtils.RenameExistingFolder(outputFolderPath);
Logger.Log($"Exporting {desiredFormat.ToString().Upper()} frames to '{Path.GetFileName(outputFolderPath)}'...");

if (desiredFormat.GetInfo().OverideExtension.ToUpper() == availableFormat.ToUpper()) // Move if frames are already in the desired format
if (desiredFormat.GetInfo().OverideExtension.Upper() == availableFormat.Upper()) // Move if frames are already in the desired format
await CopyOutputFrames(framesPath, framesFile, outputFolderPath, 1, fpsLimit, false);
else // Encode if frames are not in desired format
await FfmpegEncode.FramesToFrames(framesFile, outputFolderPath, 1, I.currentSettings.outFps, new Fraction(), desiredFormat, OutputUtils.GetImgSeqQ(I.currentSettings.outSettings));
Expand Down Expand Up @@ -301,7 +301,7 @@ public static async Task EncodeChunk(string outPath, string interpDir, int chunk
if (settings.Encoder.GetInfo().IsImageSequence) // Image Sequence output mode, not video
{
string desiredFormat = settings.Encoder.GetInfo().OverideExtension;
string availableFormat = Path.GetExtension(IoUtils.GetFilesSorted(interpDir)[0]).Remove(".").ToUpper();
string availableFormat = Path.GetExtension(IoUtils.GetFilesSorted(interpDir)[0]).Remove(".").Upper();

if (!dontEncodeFullFpsVid)
{
Expand All @@ -311,7 +311,7 @@ public static async Task EncodeChunk(string outPath, string interpDir, int chunk
if (chunkNo == 1) // Only check for existing folder on first chunk, otherwise each chunk makes a new folder
IoUtils.RenameExistingFolder(outFolderPath);

if (desiredFormat.ToUpper() == availableFormat.ToUpper()) // Move if frames are already in the desired format
if (desiredFormat.Upper() == availableFormat.Upper()) // Move if frames are already in the desired format
await CopyOutputFrames(interpDir, concatFile, outFolderPath, startNo, fpsLimit, true);
else // Encode if frames are not in desired format
await FfmpegEncode.FramesToFrames(concatFile, outFolderPath, startNo, I.currentSettings.outFps, new Fraction(), settings.Encoder, OutputUtils.GetImgSeqQ(settings), AvProcess.LogMode.Hidden);
Expand Down
4 changes: 2 additions & 2 deletions CodeLegacy/Main/InterpolateUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public static bool CheckAiAvailable(AiInfo ai, ModelCollection.ModelInfo model)
return false;
}

if (I.currentSettings.ai.NameInternal.ToUpper().Contains("CUDA") && NvApi.gpuList.Count < 1)
if (I.currentSettings.ai.NameInternal.Upper().Contains("CUDA") && NvApi.gpuList.Count < 1)
{
UiUtils.ShowMessageBox("Warning: No Nvidia GPU was detected. CUDA might fall back to CPU!\n\nTry an NCNN implementation instead if you don't have an Nvidia GPU.", UiUtils.MessageType.Error);

Expand Down Expand Up @@ -240,7 +240,7 @@ public static async Task<bool> CheckEncoderValid()
{
string enc = I.currentSettings.outSettings.Encoder.GetInfo().Name;

if (enc.ToLowerInvariant().Contains("nvenc") && !(await FfmpegCommands.IsEncoderCompatible(enc)))
if (enc.Lower().Contains("nvenc") && !(await FfmpegCommands.IsEncoderCompatible(enc)))
{
UiUtils.ShowMessageBox("NVENC encoding is not available on your hardware!\nPlease use a different encoder.", UiUtils.MessageType.Error);
I.Cancel();
Expand Down
2 changes: 1 addition & 1 deletion CodeLegacy/Media/FfmpegCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public static async Task<int> ReadFrameCountFfmpegAsync(string filePath)
try
{
string[] lines = info.SplitIntoLines();
string lastLine = lines.Last().ToLowerInvariant();
string lastLine = lines.Last().Lower();
return lastLine.Substring(0, lastLine.IndexOf("fps")).GetInt();
}
catch
Expand Down
6 changes: 3 additions & 3 deletions CodeLegacy/Media/FfmpegExtract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public static string GetTrimArg(bool input)
public static async Task ImportSingleImage(string inputFile, string outPath, Size size)
{
string sizeStr = (size.Width > 1 && size.Height > 1) ? $"-s {size.Width}x{size.Height}" : "";
bool isPng = (Path.GetExtension(outPath).ToLowerInvariant() == ".png");
bool isPng = (Path.GetExtension(outPath).Lower() == ".png");
string comprArg = isPng ? pngCompr : "";
string pixFmt = isPng ? $"rgb24 {comprArg}" : "yuv420p -color_range full";
string args = $"-i {inputFile.Wrap()} {comprArg} {sizeStr} -pix_fmt {pixFmt} -vf {GetPadFilter()} {outPath.Wrap()}";
Expand All @@ -315,7 +315,7 @@ public static async Task ImportSingleImage(string inputFile, string outPath, Siz

public static async Task ExtractSingleFrame(string inputFile, string outputPath, int frameNum)
{
bool isPng = (Path.GetExtension(outputPath).ToLowerInvariant() == ".png");
bool isPng = (Path.GetExtension(outputPath).Lower() == ".png");
string comprArg = isPng ? pngCompr : "";
string pixFmt = isPng ? $"rgb24 {comprArg}" : "yuv420p -color_range full";
string args = $"-i {inputFile.Wrap()} -vf \"select=eq(n\\,{frameNum})\" -vframes 1 -update 1 -pix_fmt {pixFmt} {outputPath.Wrap()}";
Expand All @@ -330,7 +330,7 @@ public static async Task ExtractLastFrame(string inputFile, string outputPath, S
if (IoUtils.IsPathDirectory(outputPath))
outputPath = Path.Combine(outputPath, "last.png");

bool isPng = (Path.GetExtension(outputPath).ToLowerInvariant() == ".png");
bool isPng = (Path.GetExtension(outputPath).Lower() == ".png");
string comprArg = isPng ? pngCompr : "";
string pixFmt = isPng ? $"rgb24 {comprArg}" : "yuv420p -color_range full";
string sizeStr = (size.Width > 1 && size.Height > 1) ? $"-s {size.Width}x{size.Height}" : "";
Expand Down
16 changes: 8 additions & 8 deletions CodeLegacy/Media/FfmpegUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static async Task<List<Stream>> GetStreams(string path, bool progressBar,
string title = await GetFfprobeInfoAsync(path, showStreams, "TAG:title", idx);
string codec = await GetFfprobeInfoAsync(path, showStreams, "codec_name", idx);
string codecLong = await GetFfprobeInfoAsync(path, showStreams, "codec_long_name", idx);
string pixFmt = (await GetFfprobeInfoAsync(path, showStreams, "pix_fmt", idx)).ToUpper();
string pixFmt = (await GetFfprobeInfoAsync(path, showStreams, "pix_fmt", idx)).Upper();
int kbits = (await GetFfprobeInfoAsync(path, showStreams, "bit_rate", idx)).GetInt() / 1024;
Size res = await GetMediaResolutionCached.GetSizeAsync(path);
Size sar = SizeFromString(await GetFfprobeInfoAsync(path, showStreams, "sample_aspect_ratio", idx));
Expand All @@ -86,7 +86,7 @@ public static async Task<List<Stream>> GetStreams(string path, bool progressBar,
string title = await GetFfprobeInfoAsync(path, showStreams, "TAG:title", idx);
string codec = await GetFfprobeInfoAsync(path, showStreams, "codec_name", idx);
string profile = await GetFfprobeInfoAsync(path, showStreams, "profile", idx);
if (codec.ToLowerInvariant() == "dts" && profile != "unknown") codec = profile;
if (codec.Lower() == "dts" && profile != "unknown") codec = profile;
string codecLong = await GetFfprobeInfoAsync(path, showStreams, "codec_long_name", idx);
int kbits = (await GetFfprobeInfoAsync(path, showStreams, "bit_rate", idx)).GetInt() / 1024;
int sampleRate = (await GetFfprobeInfoAsync(path, showStreams, "sample_rate", idx)).GetInt();
Expand Down Expand Up @@ -250,14 +250,14 @@ public static string[] GetEncArgs(OutputSettings settings, Size res, float fps,

if (enc == Encoder.X264)
{
string preset = Config.Get(Config.Key.ffEncPreset).ToLowerInvariant().Remove(" "); // TODO: Replace this ugly stuff with enums
string preset = Config.Get(Config.Key.ffEncPreset).Lower().Remove(" "); // TODO: Replace this ugly stuff with enums
int crf = GetCrf(settings);
args.Add($"-crf {crf} -preset {preset}");
}

if (enc == Encoder.X265)
{
string preset = Config.Get(Config.Key.ffEncPreset).ToLowerInvariant().Remove(" "); // TODO: Replace this ugly stuff with enums
string preset = Config.Get(Config.Key.ffEncPreset).Lower().Remove(" "); // TODO: Replace this ugly stuff with enums
int crf = GetCrf(settings);
args.Add($"{(crf > 0 ? $"-crf {crf}" : "-x265-params lossless=1")} -preset {preset}");
}
Expand Down Expand Up @@ -402,7 +402,7 @@ public static string GetKeyIntArg(float fps, int intervalSeconds, string arg = "

static string GetVp9Speed()
{
string preset = Config.Get(Config.Key.ffEncPreset).ToLowerInvariant().Remove(" ");
string preset = Config.Get(Config.Key.ffEncPreset).Lower().Remove(" ");
string arg = "";

if (preset == "veryslow") arg = "0";
Expand All @@ -418,7 +418,7 @@ static string GetVp9Speed()

static string GetSvtAv1Speed()
{
string preset = Config.Get(Config.Key.ffEncPreset).ToLowerInvariant().Remove(" ");
string preset = Config.Get(Config.Key.ffEncPreset).Lower().Remove(" ");
string arg = "8";

if (preset == "veryslow") arg = "3";
Expand Down Expand Up @@ -548,10 +548,10 @@ public static bool ContainerSupportsSubs(string containerExt, bool showWarningIf
{
containerExt = containerExt.Lower().Remove(".");
bool supported = (containerExt == "mp4" || containerExt == "mkv" || containerExt == "webm" || containerExt == "mov");
// Logger.Log($"Subtitles {(supported ? "are supported" : "not supported")} by {containerExt.ToUpper()}", true);
// Logger.Log($"Subtitles {(supported ? "are supported" : "not supported")} by {containerExt.Upper()}", true);

if (showWarningIfNotSupported && Config.GetBool(Config.Key.keepSubs) && !supported)
Logger.Log($"Warning: {containerExt.ToUpper()} exports do not include subtitles.");
Logger.Log($"Warning: {containerExt.Upper()} exports do not include subtitles.");

return supported;
}
Expand Down
4 changes: 2 additions & 2 deletions CodeLegacy/Media/GetVideoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public static async Task<string> GetFfprobeInfoAsync(string path, FfprobeMode mo
if (stripKeyName)
{

List<string> filtered = output.SplitIntoLines().Where(x => x.ToLowerInvariant().Contains(lineFilter.ToLowerInvariant())).ToList(); // Filter
List<string> filtered = output.SplitIntoLines().Where(x => x.Lower().Contains(lineFilter.Lower())).ToList(); // Filter
filtered = filtered.Select(x => string.Join("", x.Split('=').Skip(1))).ToList(); // Ignore everything before (and including) the first '=' sign
output = string.Join("\n", filtered);
}
else
{
output = string.Join("\n", output.SplitIntoLines().Where(x => x.ToLowerInvariant().Contains(lineFilter.ToLowerInvariant())).ToArray());
output = string.Join("\n", output.SplitIntoLines().Where(x => x.Lower().Contains(lineFilter.Lower())).ToArray());
}
}

Expand Down
2 changes: 1 addition & 1 deletion CodeLegacy/MiscUtils/FormatUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static string BeautifyFfmpegStats(string line)
public static string CapsIfShort(string codec, int capsIfShorterThan = 5)
{
if (codec.Length < capsIfShorterThan)
return codec.ToUpper();
return codec.Upper();
else
return codec.ToTitleCase();
}
Expand Down
Loading

0 comments on commit 9672c31

Please sign in to comment.