Initial Commit
This commit is contained in:
70
MapShuffler/Program.cs
Normal file
70
MapShuffler/Program.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
|
||||
try
|
||||
{
|
||||
if (args.Length == 0 || args.Contains("-h") || args.Contains("--help"))
|
||||
{
|
||||
Console.WriteLine("Usage: MapShuffler <output.txt> <maps_directory>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length != 2)
|
||||
{
|
||||
Console.Error.WriteLine("Error: Expected exactly two arguments.");
|
||||
Console.WriteLine("Usage: MapShuffler <output.txt> <maps_directory>");
|
||||
Environment.ExitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
var outputPath = args[0];
|
||||
var dirPath = args[1];
|
||||
|
||||
if (!Directory.Exists(dirPath))
|
||||
{
|
||||
Console.Error.WriteLine($"Directory not found: {dirPath}");
|
||||
Environment.ExitCode = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
var bspFiles = Directory.EnumerateFiles(dirPath)
|
||||
.Where(f => string.Equals(Path.GetExtension(f), ".bsp", StringComparison.OrdinalIgnoreCase))
|
||||
.Select(f => Path.GetFileNameWithoutExtension(f))
|
||||
.ToList();
|
||||
|
||||
Console.WriteLine($"Found {bspFiles.Count} .bsp file(s) in {dirPath}");
|
||||
|
||||
if (bspFiles.Count == 0)
|
||||
{
|
||||
File.WriteAllText(outputPath, string.Empty, Encoding.UTF8);
|
||||
Console.WriteLine($"Wrote empty file to {outputPath}");
|
||||
Environment.ExitCode = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
var rnd = Random.Shared;
|
||||
for (int i = bspFiles.Count - 1; i > 0; i--)
|
||||
{
|
||||
int j = rnd.Next(i + 1);
|
||||
var tmp = bspFiles[i];
|
||||
bspFiles[i] = bspFiles[j];
|
||||
bspFiles[j] = tmp;
|
||||
}
|
||||
|
||||
var parent = Path.GetDirectoryName(outputPath);
|
||||
if (!string.IsNullOrEmpty(parent) && !Directory.Exists(parent))
|
||||
Directory.CreateDirectory(parent);
|
||||
|
||||
File.WriteAllLines(outputPath, bspFiles, Encoding.UTF8);
|
||||
Console.WriteLine($"Wrote {bspFiles.Count} entries to {outputPath}");
|
||||
Environment.ExitCode = 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Error: {ex.Message}");
|
||||
Environment.ExitCode = 99;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user