mirror of
https://github.com/whoswhip/RhythiaReplayExporter.git
synced 2026-12-04 07:08:42 +00:00
init
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
using Microsoft.Data.Sqlite;
|
||||
using System.Globalization;
|
||||
|
||||
namespace RhythiaReplayExporter;
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||
if (string.IsNullOrWhiteSpace(appData))
|
||||
{
|
||||
Console.WriteLine("Failed to find app data folder.");
|
||||
Environment.Exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
string rhythia = Path.Combine(appData, "CapoRhythia");
|
||||
if (!Directory.Exists(rhythia))
|
||||
{
|
||||
Console.WriteLine("CapoRhythia directory doesn't exist in app data.");
|
||||
Environment.Exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
string database = Path.Combine(rhythia, "rhythia.db");
|
||||
if (!File.Exists(database))
|
||||
{
|
||||
Console.WriteLine("Rhythia user database doesn't exist.");
|
||||
Environment.Exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
string workingDir = Environment.CurrentDirectory;
|
||||
string replaysDir = Path.Combine(workingDir, "replays");
|
||||
if (args.Length > 0)
|
||||
replaysDir = args[0];
|
||||
|
||||
Directory.CreateDirectory(replaysDir);
|
||||
|
||||
using SqliteConnection con = new($"Data Source={database}");
|
||||
con.Open();
|
||||
|
||||
using SqliteCommand comm = con.CreateCommand();
|
||||
comm.CommandText = "SELECT CreatedAt, LegacyMapId, Replay FROM Scores;";
|
||||
using var reader = comm.ExecuteReader();
|
||||
|
||||
int count = 0;
|
||||
while (reader.Read())
|
||||
{
|
||||
DateTime createdAt = DateTime.ParseExact(reader.GetString(0), "yyyy-MM-dd HH:mm:ss.FFFFFFF", CultureInfo.InvariantCulture);
|
||||
string legacyMapId = reader.GetString(1);
|
||||
byte[] replay = reader.GetFieldValue<byte[]>(2);
|
||||
|
||||
string filename = $"{createdAt:yyyy-MM-dd-HHmmss}-{legacyMapId.Replace(" ", "_")}.rhr";
|
||||
string path = Path.Combine(replaysDir, filename);
|
||||
File.WriteAllBytes(path, replay);
|
||||
Console.WriteLine($"Wrote {filename} to {path}");
|
||||
count++;
|
||||
}
|
||||
Console.WriteLine($"Exported {count} replays to {replaysDir}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user