Skip to content

Commit

Permalink
Rename io package to SimpleIO
Browse files Browse the repository at this point in the history
  • Loading branch information
shana committed Nov 8, 2019
1 parent 84bf326 commit 238780d
Show file tree
Hide file tree
Showing 93 changed files with 596 additions and 584 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace LocalTools
{
using SpoiledCat.Json;
using SpoiledCat.NiceIO;
using SpoiledCat.SimpleIO;
using SpoiledCat.Utilities;

/// <summary>
Expand All @@ -10,11 +10,11 @@
public struct Asset
{
private string hash;
private NPath path;
private SPath path;
private UriString url;
private bool needsUnzip;

public Asset(Asset asset, NPath localPath)
public Asset(Asset asset, SPath localPath)
{
hash = asset.hash;
path = asset.path;
Expand All @@ -25,10 +25,10 @@ public Asset(Asset asset, NPath localPath)
}

[NotSerialized] public UriString Url { get => url; set => url = value; }
[NotSerialized] public NPath Path { get => path; set => path = value; }
[NotSerialized] public SPath Path { get => path; set => path = value; }
[NotSerialized] public string Hash { get => hash; set => hash = value; }
[NotSerialized] public bool NeedsUnzip { get => needsUnzip; set => needsUnzip = value; }
[NotSerialized] public NPath LocalPath { get; set; }
[NotSerialized] public SPath LocalPath { get; set; }
[NotSerialized] public string Filename => url?.Filename ?? "";
[NotSerialized] public bool NeedsDownload { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
{
using System;
using System.Security.Cryptography;
using SpoiledCat.NiceIO;
using SpoiledCat.SimpleIO;

public static class Extensions
{
public static string ToMD5(this NPath path)
public static string ToMD5(this SPath path)
{
byte[] computeHash;
using (var md5 = MD5.Create())
{
using (var stream = NPath.FileSystem.OpenRead(path.MakeAbsolute()))
using (var stream = SPath.FileSystem.OpenRead(path.MakeAbsolute()))
{
computeHash = md5.ComputeHash(stream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using SpoiledCat.Json;
using SpoiledCat.NiceIO;
using SpoiledCat.SimpleIO;

public struct Index
{
Expand All @@ -20,10 +20,10 @@ public Index(List<Asset> assets)
this.assets = assets;
}

public static Index Load(NPath indexFile) => indexFile.ReadAllText().FromJson<Index>(true, false);
public static Index Load(string indexFile) => Load(indexFile.ToNPath());
public static Index Load(SPath indexFile) => indexFile.ReadAllText().FromJson<Index>(true, false);
public static Index Load(string indexFile) => Load(indexFile.ToSPath());

public void Save(NPath indexFile) => indexFile.WriteAllText(this.ToJson(true, false));
public void Save(string indexFile) => Save(indexFile.ToNPath());
public void Save(SPath indexFile) => indexFile.WriteAllText(this.ToJson(true, false));
public void Save(string indexFile) => Save(indexFile.ToSPath());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "LargeAssetManager",
"references": [
"com.spoiledcat.niceio",
"com.spoiledcat.simpleio",
"com.spoiledcat.simplejson",
"com.spoiledcat.logging",
"com.spoiledcat.threading",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using LocalTools;
using SpoiledCat.Json;
using SpoiledCat.Logging;
using SpoiledCat.NiceIO;
using SpoiledCat.SimpleIO;
using SpoiledCat.Threading;
using SpoiledCat.Utilities;
using UnityEditor;
Expand All @@ -20,15 +20,15 @@ public class LargeAssetManager

static LargeAssetManager()
{
PocoJsonSerializerStrategy.RegisterCustomTypeHandler<NPath>(
value => (((NPath)value).ToString(SlashMode.Forward), true),
PocoJsonSerializerStrategy.RegisterCustomTypeHandler<SPath>(
value => (((SPath)value).ToString(SlashMode.Forward), true),
(value, type) => {
string str = value as string;
if (!string.IsNullOrEmpty(str))
{
return (new NPath(str), true);
return (new SPath(str), true);
}
return (NPath.Default, true);
return (SPath.Default, true);
});

PocoJsonSerializerStrategy.RegisterCustomTypeHandler<UriString>(value => (value.ToString(), true),
Expand Down Expand Up @@ -66,7 +66,7 @@ private static void ClearProgress()
}


public static void UpdateIndexFromFilesInFolder(NPath template, NPath indexPath, NPath path)
public static void UpdateIndexFromFilesInFolder(SPath template, SPath indexPath, SPath path)
{
var runTask = UpdateIndexFromFilesInFolderTask(path, indexPath, template);

Expand All @@ -80,7 +80,7 @@ public static void UpdateIndexFromFilesInFolder(NPath template, NPath indexPath,
.Start();
}

public static ITask UpdateIndexFromFilesInFolderTask(NPath folderWithFiles, NPath indexFileToGenerate, NPath? indexTemplate = null)
public static ITask UpdateIndexFromFilesInFolderTask(SPath folderWithFiles, SPath indexFileToGenerate, SPath? indexTemplate = null)
{
Index? templateIndex = null;
if (indexTemplate.HasValue && indexTemplate.Value.FileExists())
Expand All @@ -105,7 +105,7 @@ public static ITask UpdateIndexFromFilesInFolderTask(NPath folderWithFiles, NPat
else
{
asset.LocalPath = file;
asset.Path = file.FileNameWithoutExtension.ToNPath();
asset.Path = file.FileNameWithoutExtension.ToSPath();
asset.NeedsUnzip = file.ExtensionWithDot == ".zip" ? true : false;
asset.Url = $"{DefaultWebServerUrl}:{DefaultWebServerPort}/assets/{dt}/{file.FileName}";
}
Expand Down Expand Up @@ -173,11 +173,11 @@ public static void JustUnzip()
{
var index = Index.Load("index.json");

var downloads = "Downloads".ToNPath().MakeAbsolute();
var downloads = "Downloads".ToSPath().MakeAbsolute();
List<Asset> assetList = new List<Asset>();
foreach (var asset in index.Assets.Where(x => x.NeedsUnzip))
{
NPath file = downloads.Combine(asset.Filename);
SPath file = downloads.Combine(asset.Filename);
if (file.FileExists())
assetList.Add(new Asset(asset, downloads.Combine(asset.Filename)));
}
Expand All @@ -197,14 +197,14 @@ public static void JustUnzip()

private static TaskQueue<Asset> CalculateWhatNeedsToBeDownloaded(Index index)
{
var downloads = "Downloads".ToNPath().MakeAbsolute();
var downloads = "Downloads".ToSPath().MakeAbsolute();
List<Asset> downloadList = new List<Asset>();

TaskQueue<Asset> t = new TaskQueue<Asset>(TaskManager) { Message = "Calculating hashes..." };
foreach (var entry in index.Assets)
{
t.Queue(new FuncTask<Asset, Asset>(TaskManager, (_, asset) => {
NPath file;
SPath file;
if (asset.NeedsUnzip)
{
file = downloads.Combine(asset.Filename);
Expand Down Expand Up @@ -261,9 +261,9 @@ public static ITask<List<Asset>> DownloadIfNeeded(Index index)
});
}

public static TaskQueue<NPath> Unzip(List<Asset> assetList)
public static TaskQueue<SPath> Unzip(List<Asset> assetList)
{
var unzipper = new TaskQueue<NPath>(TaskManager);
var unzipper = new TaskQueue<SPath>(TaskManager);
foreach (var asset in assetList.Where(x => x.NeedsUnzip))
{
var unzipStamp = asset.LocalPath.Parent.Combine($".{asset.Filename}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Threading.Tasks;
using SpoiledCat.Logging;
using SpoiledCat.NiceIO;
using SpoiledCat.SimpleIO;
using SpoiledCat.ProcessManager;
using SpoiledCat.Threading;
using SpoiledCat.UI;
Expand Down Expand Up @@ -76,10 +76,10 @@ private void JustUnzip()
private void CreateIndex()
{
LargeAssetManager.TaskManager = TaskManager;
string folder = EditorUtility.OpenFolderPanel("Select Folder with zip files to add to the index", "../../Helpers/Helper.WebServer/files/assets".ToNPath().Resolve(), "");
string folder = EditorUtility.OpenFolderPanel("Select Folder with zip files to add to the index", "../../Helpers/Helper.WebServer/files/assets".ToSPath().Resolve(), "");
if (!string.IsNullOrEmpty(folder))
{
LargeAssetManager.UpdateIndexFromFilesInFolder("index-template.json".ToNPath(), "index.json".ToNPath(), folder.ToNPath());
LargeAssetManager.UpdateIndexFromFilesInFolder("index-template.json".ToSPath(), "index.json".ToSPath(), folder.ToSPath());
}
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public override async void OnUI()
if (GUILayout.Button("Start Web Server"))
{
webServerTask = new ProcessTaskLongRunning(TaskManager, ProcessEnvironment,
"Packages/com.spoiledcat.processmanager/Tests/Helpers~/Helper.CommandLine.exe".ToNPath().Resolve(),
"Packages/com.spoiledcat.processmanager/Tests/Helpers~/Helper.CommandLine.exe".ToSPath().Resolve(),
$"-w -p {webServerPort}").Configure(new ProcessManager(Environment, TaskManager.Token));


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"dependencies": {
"com.spoiledcat.environment": "file:../../../../build/packages/com.spoiledcat.environment",
"com.spoiledcat.logging": "file:../../../../build/packages/com.spoiledcat.logging",
"com.spoiledcat.niceio": "file:../../../../build/packages/com.spoiledcat.niceio",
"com.spoiledcat.simpleio": "file:../../../../build/packages/com.spoiledcat.simpleio",
"com.spoiledcat.processmanager": "file:../../../../build/packages/com.spoiledcat.processmanager",
"com.spoiledcat.processmanager.tests": "file:../../../../build/packages/com.spoiledcat.processmanager.tests",
"com.spoiledcat.quick-console": "file:../../../../build/packages/com.spoiledcat.quick-console",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace LocalTools
{
using SpoiledCat.Json;
using SpoiledCat.NiceIO;
using SpoiledCat.SimpleIO;
using SpoiledCat.Utilities;

/// <summary>
Expand All @@ -10,11 +10,11 @@
public struct Asset
{
private string hash;
private NPath path;
private SPath path;
private UriString url;
private bool needsUnzip;

public Asset(Asset asset, NPath localPath)
public Asset(Asset asset, SPath localPath)
{
hash = asset.hash;
path = asset.path;
Expand All @@ -25,10 +25,10 @@ public Asset(Asset asset, NPath localPath)
}

[NotSerialized] public UriString Url { get => url; set => url = value; }
[NotSerialized] public NPath Path { get => path; set => path = value; }
[NotSerialized] public SPath Path { get => path; set => path = value; }
[NotSerialized] public string Hash { get => hash; set => hash = value; }
[NotSerialized] public bool NeedsUnzip { get => needsUnzip; set => needsUnzip = value; }
[NotSerialized] public NPath LocalPath { get; set; }
[NotSerialized] public SPath LocalPath { get; set; }
[NotSerialized] public string Filename => url?.Filename ?? "";
[NotSerialized] public bool NeedsDownload { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
{
using System;
using System.Security.Cryptography;
using SpoiledCat.NiceIO;
using SpoiledCat.SimpleIO;

public static class Extensions
{
public static string ToMD5(this NPath path)
public static string ToMD5(this SPath path)
{
byte[] computeHash;
using (var md5 = MD5.Create())
{
using (var stream = NPath.FileSystem.OpenRead(path.MakeAbsolute()))
using (var stream = SPath.FileSystem.OpenRead(path.MakeAbsolute()))
{
computeHash = md5.ComputeHash(stream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using SpoiledCat.Json;
using SpoiledCat.NiceIO;
using SpoiledCat.SimpleIO;

public struct Index
{
Expand All @@ -20,10 +20,10 @@ public Index(List<Asset> assets)
this.assets = assets;
}

public static Index Load(NPath indexFile) => indexFile.ReadAllText().FromJson<Index>(true, false);
public static Index Load(string indexFile) => Load(indexFile.ToNPath());
public static Index Load(SPath indexFile) => indexFile.ReadAllText().FromJson<Index>(true, false);
public static Index Load(string indexFile) => Load(indexFile.ToSPath());

public void Save(NPath indexFile) => indexFile.WriteAllText(this.ToJson(true, false));
public void Save(string indexFile) => Save(indexFile.ToNPath());
public void Save(SPath indexFile) => indexFile.WriteAllText(this.ToJson(true, false));
public void Save(string indexFile) => Save(indexFile.ToSPath());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "LargeAssetManager",
"references": [
"com.spoiledcat.niceio",
"com.spoiledcat.simpleio",
"com.spoiledcat.simplejson",
"com.spoiledcat.logging",
"com.spoiledcat.threading",
Expand Down
Loading

0 comments on commit 238780d

Please sign in to comment.