Skip to content

Commit

Permalink
actually works now,
Browse files Browse the repository at this point in the history
coverts to legacy modcsv in the buildzone()
also created zone_source dir is not existing
  • Loading branch information
kruumy committed Mar 9, 2023
1 parent b5f4fbe commit 59c5a09
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 14 deletions.
58 changes: 58 additions & 0 deletions EasyZoneBuilder.Core/LegacyModCSV.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using EasyZoneBuilder.Core.Interfaces;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace EasyZoneBuilder.Core
{
public class LegacyModCSV : Dictionary<string, AssetType>, IFileInfo, ISync
{
public LegacyModCSV( FileInfo File )
{
this.File = File;
if ( File.Exists )
{
Pull();
}
}

public LegacyModCSV( ModCSV csv )
{
foreach ( KeyValuePair<string, ModCSV.EntryInfomation> entry in csv )
{
this[ entry.Key ] = entry.Value.AssetType;
}
}

public FileInfo File { get; private set; }

public void Pull()
{
if ( !File.Exists )
{
Push();
}
this.Clear();
foreach ( string line in System.IO.File.ReadAllLines(this.File.FullName) )
{
string[] splitLine = line.Split(new char[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);
this[ splitLine[ 1 ].Trim() ] = AssetTypeUtil.Parse(splitLine[ 0 ].Trim());
}
}

public void Push()
{
StringBuilder sb = new StringBuilder();
foreach ( KeyValuePair<string, AssetType> item in this )
{
sb.AppendLine($"{item.Value},{item.Key}");
}
System.IO.File.WriteAllText(File.FullName, sb.ToString());
}

public TempFileCopy TempCopy( FileInfo destination )
{
return new TempFileCopy(this.File, destination);
}
}
}
9 changes: 0 additions & 9 deletions EasyZoneBuilder.Core/ModCSV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ public void Pull()
}
}

public void Move( FileInfo File )
{
if ( this.File.FullName != File.FullName )
{
System.IO.File.Move(this.File.FullName, File.FullName);
}
this.File = File;
}

public TempFileCopy TempCopy( FileInfo destination )
{
return new TempFileCopy(this.File, destination);
Expand Down
16 changes: 11 additions & 5 deletions EasyZoneBuilder.Core/ZoneBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static async Task<string> Execute( params string[] commands )
{
StringBuilder args = new StringBuilder();
args.Append("-zonebuilder -stdout");
foreach ( var com in commands )
foreach ( string com in commands )
{
args.Append(" +");
args.Append(com);
Expand Down Expand Up @@ -74,7 +74,7 @@ public static async Task<string[]> ExecuteLines( params string[] commands )
public static async Task<IEnumerable<string>> ListAssets( AssetType assetType, params string[] zones )
{
List<string> command = new List<string>(zones.Length + 1);
foreach ( var item in zones )
foreach ( string item in zones )
{
command.Add("loadzone " + item);
}
Expand All @@ -96,7 +96,7 @@ public static async Task<IEnumerable<string>> ListAssets( AssetType assetType, p

public static async Task<IEnumerable<string>> ListAssets( AssetType assetType, FileInfo file )
{
var destination = new FileInfo(Path.Combine(TargetExecutable.Directory.FullName, @"zone\english", file.Name));
FileInfo destination = new FileInfo(Path.Combine(TargetExecutable.Directory.FullName, @"zone\english", file.Name));
using ( TempFileCopy temp = new TempFileCopy(file, destination) )
{
string command = Path.GetFileNameWithoutExtension(file.FullName);
Expand All @@ -107,15 +107,21 @@ public static async Task<IEnumerable<string>> ListAssets( AssetType assetType, F
public static async Task BuildZone( ModCSV csv, FileInfo destination )
{
List<string> commands = new List<string>();
foreach ( var zone in csv.Values )
foreach ( ModCSV.EntryInfomation zone in csv.Values )
{
commands.Add("loadzone " + zone.Zone);
}
commands = commands.Distinct().ToList();
FileInfo csvdest = new FileInfo(Path.Combine(TargetExecutable.Directory.FullName, @"zone_source", csv.File.Name));
if ( !csvdest.Directory.Exists )
{
csvdest.Directory.Create();
}
csv.Push();
using ( var tempcopy = csv.TempCopy(csvdest) )
using ( TempFileCopy tempcopy = csv.TempCopy(csvdest) )
{
LegacyModCSV legcsv = new LegacyModCSV(csvdest);
legcsv.Push();
commands.Add("buildzone mod");
await ExecuteLines(commands.ToArray());
}
Expand Down

0 comments on commit 59c5a09

Please sign in to comment.