Skip to content

Commit

Permalink
Fix ExtractJsonFileName method to handle filenames without paths
Browse files Browse the repository at this point in the history
Ensured the method correctly returns the filename if no path is present or when a valid path and ".json" suffix are found.
  • Loading branch information
characharm authored Sep 12, 2024
1 parent 97e95ec commit a0a5961
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions BackupManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,46 @@ private void HandleRestoreCommand(CCSPlayerController? player, string commandArg
}
public static string ExtractJsonFileName(string input)
{

if (string.IsNullOrEmpty(input))
{
return string.Empty;
}


if (!input.Contains('\\') && !input.Contains('/'))
{
// If no directory separators are found, return the input as-is
return input;
}

// Find the index of ".json" in the input
int jsonIndex = input.IndexOf(".json", StringComparison.OrdinalIgnoreCase);
if (jsonIndex != -1)
{

int startIndex = input.LastIndexOfAny(new[] { '\\', '/' }, jsonIndex);
string fileName = input.Substring(startIndex + 1, jsonIndex - startIndex + 5);


return fileName;
if (startIndex >= 0)
{

int length = jsonIndex - startIndex + 5;


if (length > 0 && startIndex + 1 + length <= input.Length)
{
string fileName = input.Substring(startIndex + 1, length);
return fileName;
}
}
}


return string.Empty;
}



private void RestoreRoundBackup(CCSPlayerController? player, string fileName)
{

Expand Down

0 comments on commit a0a5961

Please sign in to comment.