Skip to content

Commit

Permalink
use localPath for spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
exp111 committed Sep 12, 2023
1 parent c01cfce commit 7adfa12
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions Turbulence.ModelGenerator/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public static class Converter
/// <param name="modelPath">The directory to put the generated records.</param>
public static async Task Convert(Uri tablesPath, Uri modelPath)
{
Directory.CreateDirectory(modelPath.AbsolutePath);
Directory.CreateDirectory(modelPath.LocalPath);

// First, extract all record names and their namespaces
foreach (var tableDir in Directory.GetDirectories(tablesPath.AbsolutePath))
foreach (var tableDir in Directory.GetDirectories(tablesPath.LocalPath))
{
foreach (var tableFile in Directory.GetFiles(tableDir))
{
Expand All @@ -47,9 +47,9 @@ public static async Task Convert(Uri tablesPath, Uri modelPath)
}

// Assumes that the depth level is exactly 1 deep
foreach (var tableDir in Directory.GetDirectories(tablesPath.AbsolutePath))
foreach (var tableDir in Directory.GetDirectories(tablesPath.LocalPath))
{
var modelDir = Path.Combine(modelPath.AbsolutePath, tableDir.Split(Path.DirectorySeparatorChar)[^1]);
var modelDir = Path.Combine(modelPath.LocalPath, tableDir.Split(Path.DirectorySeparatorChar)[^1]);
Directory.CreateDirectory(modelDir);

foreach (var tableFile in Directory.GetFiles(tableDir))
Expand Down Expand Up @@ -473,7 +473,7 @@ private static string PrettifyDescription(string description)
// Ran after conversion is done, for example to add missing classes
public static void PostConvert(Uri modelsPath)
{
File.WriteAllText(Path.Combine(modelsPath.AbsolutePath, "DiscordMessageComponents", "MessageComponent.cs"),
File.WriteAllText(Path.Combine(modelsPath.LocalPath, "DiscordMessageComponents", "MessageComponent.cs"),
@"using System.Text.Json.Serialization;
namespace Turbulence.API.Discord.Models.DiscordMessageComponents;
Expand All @@ -495,7 +495,7 @@ public record MessageComponent {
public required dynamic[] Components { get; init; }
}");

File.WriteAllText(Path.Combine(modelsPath.AbsolutePath, "DiscordGateway", "Gateway.cs"),
File.WriteAllText(Path.Combine(modelsPath.LocalPath, "DiscordGateway", "Gateway.cs"),
@"using System.Text.Json.Serialization;
namespace Turbulence.API.Discord.Models.DiscordGateway;
Expand All @@ -514,7 +514,7 @@ public record Gateway {
public required Uri Url { get; init; }
}");

File.WriteAllText(Path.Combine(modelsPath.AbsolutePath, "Error.cs"),
File.WriteAllText(Path.Combine(modelsPath.LocalPath, "Error.cs"),
@"using System.Text.Json.Serialization;
namespace Turbulence.API.Discord.Models;
Expand Down Expand Up @@ -544,7 +544,7 @@ public record Error {
public dynamic? Errors { get; init; }
}");

File.WriteAllText(Path.Combine(modelsPath.AbsolutePath, "DiscordGatewayEvents", "GatewayPayload.cs"),
File.WriteAllText(Path.Combine(modelsPath.LocalPath, "DiscordGatewayEvents", "GatewayPayload.cs"),
@"using System.Text.Json.Serialization;
namespace Turbulence.API.Discord.Models.DiscordGateway;
Expand Down
12 changes: 6 additions & 6 deletions Turbulence.ModelGenerator/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ public static class Downloader
public static async Task DownloadFiles(Uri root, List<string> files, Uri outPath)
{
// If downloads directory already exists, give the option to delete it or stop running
if (Directory.Exists(outPath.AbsolutePath))
if (Directory.Exists(outPath.LocalPath))
{
Console.WriteLine($"{outPath.AbsolutePath} already exists. Delete? (y/N)");
Console.WriteLine($"{outPath.LocalPath} already exists. Delete? (y/N)");

if (Console.ReadKey(true).KeyChar is 'y' or 'Y')
{
Directory.Delete(outPath.AbsolutePath, true);
Directory.Delete(outPath.LocalPath, true);
}
else
{
Expand All @@ -28,19 +28,19 @@ public static async Task DownloadFiles(Uri root, List<string> files, Uri outPath
foreach (var file in files)
{
Uri toDownload = new(root + "/" + file);
Uri outputFile = new(Path.Combine(outPath.AbsolutePath, file));
Uri outputFile = new(Path.Combine(outPath.LocalPath, file));

Console.Write($"Downloading file {Path.GetFileName(file)}...");

// Download the file
var response = await client.GetAsync(toDownload);

// Create a directory for the file
Directory.CreateDirectory(Path.GetDirectoryName(outputFile.AbsolutePath)
Directory.CreateDirectory(Path.GetDirectoryName(outputFile.LocalPath)
?? throw new Exception("Can't get directory name. Files or tempPath are most likely malformed."));

// Write file
await using var fs = new FileStream(outputFile.AbsolutePath, FileMode.Create);
await using var fs = new FileStream(outputFile.LocalPath, FileMode.Create);
await response.Content.CopyToAsync(fs);

Console.WriteLine(" done");
Expand Down
6 changes: 3 additions & 3 deletions Turbulence.ModelGenerator/Generate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ public static class Generate
{
public static async Task Main(string[] args)
{
Uri downloadPath = new(Path.Combine(Config.TempPath.AbsolutePath, "Download"));
Uri tablesPath = new(Path.Combine(Config.TempPath.AbsolutePath, "Tables"));
Uri downloadPath = new(Path.Combine(Config.TempPath.LocalPath, "Download"));
Uri tablesPath = new(Path.Combine(Config.TempPath.LocalPath, "Tables"));

await DownloadFiles(Config.DocsRoot, Config.MdFiles, downloadPath);
PreExtract(downloadPath);
await ExtractTables(downloadPath, tablesPath);
Directory.Delete(downloadPath.AbsolutePath, true);
Directory.Delete(downloadPath.LocalPath, true);

await Convert(tablesPath, Config.OutPath);
PostConvert(Config.OutPath);
Expand Down
6 changes: 3 additions & 3 deletions Turbulence.ModelGenerator/Preprocessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static async Task ExtractTables(Uri inPath, Uri outPath)
// List to keep track of written files, so we can make sure there are no duplicates
List<string> writtenFiles = new();

foreach (var file in Directory.EnumerateFiles(inPath.AbsolutePath, "*.*", SearchOption.AllDirectories))
foreach (var file in Directory.EnumerateFiles(inPath.LocalPath, "*.*", SearchOption.AllDirectories))
{
using StreamReader reader = new(file);

Expand Down Expand Up @@ -87,7 +87,7 @@ public static async Task ExtractTables(Uri inPath, Uri outPath)
// Suffix namespaces with Discord so records and namespaces won't have the same name
dir = $"Discord{dir}";

dir = Path.Combine(outPath.AbsolutePath, dir);
dir = Path.Combine(outPath.LocalPath, dir);

var filename = Path.Combine(dir, name);

Expand Down Expand Up @@ -162,7 +162,7 @@ public static void PreExtract(Uri path)
var inconsistentHeaderCount = false;
var nameFieldCount = false;

foreach (var file in Directory.EnumerateFiles(path.AbsolutePath, "*.*", SearchOption.AllDirectories))
foreach (var file in Directory.EnumerateFiles(path.LocalPath, "*.*", SearchOption.AllDirectories))
{
var text = File.ReadAllText(file);

Expand Down

0 comments on commit 7adfa12

Please sign in to comment.