Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 committed Jan 31, 2023
1 parent 5a15a5d commit fe473d8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 28 deletions.
100 changes: 74 additions & 26 deletions src/SerialLoops.Lib/IO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,89 @@ namespace SerialLoops.Lib
{
public static class IO
{
private class IODirectory
{
public string Name { get; set; }
public IODirectory[] Subdirectories { get; set; }
public IOFile[] Files { get; set; }

public IODirectory(string name, IODirectory[] subdirectories, IOFile[] files)
{
Name = name;
Subdirectories = subdirectories;
Files = files;
}

public void Create(string basePath)
{
string dirPath = Path.Combine(basePath, Name);
Directory.CreateDirectory(dirPath);
foreach (IOFile file in Files)
{
File.Copy(file.FilePath, Path.Combine(dirPath, file.Name));
}
foreach (IODirectory subdirectory in Subdirectories)
{
subdirectory.Create(dirPath);
}
}
}

private class IOFile
{
public string FilePath { get; set; }
public string Name { get; set; }

public IOFile(string path)
{
FilePath = path;
Name = Path.GetFileName(FilePath);
}

public IOFile(string path, string name)
{
FilePath = path;
Name = name;
}
}

public static void OpenRom(Project project, string romPath)
{
// Unpack the ROM, creating the two project directories
NdsProjectFile.Create(project.Name, romPath, Path.Combine(project.BaseDirectory, "rom"));
NdsProjectFile.Create(project.Name, romPath, Path.Combine(project.IterativeDirectory, "rom"));

// Create our structure for building the ROM
Directory.CreateDirectory(Path.Combine(project.BaseDirectory, "original", "archives"));
Directory.CreateDirectory(Path.Combine(project.BaseDirectory, "original", "overlay"));
Directory.CreateDirectory(Path.Combine(project.BaseDirectory, "original", "bgm"));
Directory.CreateDirectory(Path.Combine(project.BaseDirectory, "original", "vce"));
Directory.CreateDirectory(Path.Combine(project.IterativeDirectory, "original", "archives"));
Directory.CreateDirectory(Path.Combine(project.IterativeDirectory, "original", "overlay"));
Directory.CreateDirectory(Path.Combine(project.IterativeDirectory, "original", "bgm"));
Directory.CreateDirectory(Path.Combine(project.IterativeDirectory, "original", "vce"));
Directory.CreateDirectory(Path.Combine(project.BaseDirectory, "src", "source"));
Directory.CreateDirectory(Path.Combine(project.IterativeDirectory, "src", "source"));
Directory.CreateDirectory(Path.Combine(project.BaseDirectory, "src", "replSource"));
Directory.CreateDirectory(Path.Combine(project.IterativeDirectory, "src", "replSource"));
Directory.CreateDirectory(Path.Combine(project.BaseDirectory, "src", "overlays"));
Directory.CreateDirectory(Path.Combine(project.IterativeDirectory, "src", "overlays"));
IODirectory originalDirectoryTree = new("original", new IODirectory[]
{
new("archives", Array.Empty<IODirectory>(), Array.Empty<IOFile>()),
new("overlay", Array.Empty<IODirectory>(), Array.Empty<IOFile>()),
new("bgm", Array.Empty<IODirectory>(), Array.Empty<IOFile>()),
new("vce", Array.Empty<IODirectory>(), Array.Empty<IOFile>()),
}, Array.Empty<IOFile>());
IODirectory srcDirectoryTree = new("src", new IODirectory[]
{
new("source", Array.Empty<IODirectory>(), Array.Empty<IOFile>()),
new("replSource", Array.Empty<IODirectory>(), Array.Empty<IOFile>()),
new("overlays", Array.Empty<IODirectory>(), new IOFile[]
{
new(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sources", "linker.x")),
new(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sources", "Makefile_overlay"), "Makefile"),
}),
},
new IOFile[]
{
new(Path.Combine(project.BaseDirectory, "rom", "arm9.bin")),
new(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sources", "linker.x")),
new(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sources", "Makefile_main"), "Makefile"),
});
originalDirectoryTree.Create(project.BaseDirectory);
originalDirectoryTree.Create(project.IterativeDirectory);
srcDirectoryTree.Create(project.BaseDirectory);
srcDirectoryTree.Create(project.IterativeDirectory);


// Copy out the files we need to build the ROM
File.Copy(Path.Combine(project.BaseDirectory, "rom", "arm9.bin"), Path.Combine(project.BaseDirectory, "src", "arm9.bin"));
File.Copy(Path.Combine(project.IterativeDirectory, "rom", "arm9.bin"), Path.Combine(project.IterativeDirectory, "src", "arm9.bin"));
CopyFiles(Path.Combine(project.BaseDirectory, "rom", "data"), Path.Combine(project.BaseDirectory, "original", "archives"), "*.bin");
CopyFiles(Path.Combine(project.IterativeDirectory, "rom", "data"), Path.Combine(project.IterativeDirectory, "original", "archives"), "*.bin");
CopyFiles(Path.Combine(project.BaseDirectory, "rom", "overlay"), Path.Combine(project.BaseDirectory, "original", "overlay"));
Expand All @@ -48,16 +106,6 @@ public static void OpenRom(Project project, string romPath)
CopyFiles(Path.Combine(project.BaseDirectory, "rom", "data", "vce"), Path.Combine(project.BaseDirectory, "original", "vce"));
CopyFiles(Path.Combine(project.IterativeDirectory, "rom", "data", "vce"), Path.Combine(project.IterativeDirectory, "original", "vce"));
}

// Copy out static files used during build
File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sources", "linker.x"), Path.Combine(project.BaseDirectory, "src", "linker.x"));
File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sources", "linker.x"), Path.Combine(project.IterativeDirectory, "src", "linker.x"));
File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sources", "linker.x"), Path.Combine(project.BaseDirectory, "src", "overlays", "linker.x"));
File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sources", "linker.x"), Path.Combine(project.IterativeDirectory, "src", "overlays", "linker.x"));
File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sources", "Makefile_main"), Path.Combine(project.BaseDirectory, "src", "Makefile"));
File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sources", "Makefile_main"), Path.Combine(project.IterativeDirectory, "src", "Makefile"));
File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sources", "Makefile_overlay"), Path.Combine(project.BaseDirectory, "src", "overlays", "Makefile"));
File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sources", "Makefile_overlay"), Path.Combine(project.IterativeDirectory, "src", "overlays", "Makefile"));
}

public static void FetchAssets(Project project, Uri assetsRepoZip, Uri stringsRepoZip, ILogger log)
Expand Down
4 changes: 3 additions & 1 deletion src/SerialLoops.Lib/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace SerialLoops.Lib
{
public class Project
{
public const string PROJECT_FORMAT = "slproj";

public string Name { get; set; }
public string LangCode { get; set; }
public string MainDirectory { get; set; }
Expand Down Expand Up @@ -47,7 +49,7 @@ public Project(string name, string langCode, Config config, ILogger log)
try
{
Directory.CreateDirectory(MainDirectory);
File.WriteAllText(Path.Combine(MainDirectory, $"{Name}.seproj"), JsonSerializer.Serialize(this));
File.WriteAllText(Path.Combine(MainDirectory, $"{Name}.{PROJECT_FORMAT}"), JsonSerializer.Serialize(this));
Directory.CreateDirectory(BaseDirectory);
Directory.CreateDirectory(IterativeDirectory);
}
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops/MainForm.eto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void NewProjectCommand_Executed(object sender, EventArgs e)
private void OpenProject_Executed(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new() { Directory = new Uri(CurrentConfig.ProjectsDirectory) };
openFileDialog.Filters.Add(new("Serial Loops Project", ".seproj"));
openFileDialog.Filters.Add(new("Serial Loops Project", $".{Project.PROJECT_FORMAT}"));
if (openFileDialog.ShowDialog(this) == DialogResult.Ok)
{
OpenProject = Project.OpenProject(openFileDialog.FileName, CurrentConfig, _log);
Expand Down

0 comments on commit fe473d8

Please sign in to comment.