mirror of
https://github.com/LazyDuchess/OpenTS2.git
synced 2025-01-22 16:21:47 -05:00
Clean up filesystem class, fix file changes in DBPFFile, Add DBPFFileTest
This commit is contained in:
parent
5af1a6bde9
commit
c7c04c5aed
11 changed files with 91 additions and 58 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -73,3 +73,6 @@ crashlytics-build.properties
|
||||||
|
|
||||||
# OpenTS2 personal configuration
|
# OpenTS2 personal configuration
|
||||||
config.json
|
config.json
|
||||||
|
|
||||||
|
# OpenTS2 - Reserved for CI output
|
||||||
|
/[Tt]est[Ff]iles/
|
|
@ -23,7 +23,8 @@ namespace OpenTS2.Content.Changes
|
||||||
GlobalTGI = tgi.LocalGroupID(package.GroupID),
|
GlobalTGI = tgi.LocalGroupID(package.GroupID),
|
||||||
InternalTGI = tgi,
|
InternalTGI = tgi,
|
||||||
Dynamic = true,
|
Dynamic = true,
|
||||||
Package = package
|
Package = package,
|
||||||
|
FileSize = (uint)FileData.Length
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public ChangedFile(AbstractAsset asset, byte[] fileData) : this(fileData, asset.InternalTGI, asset.Package)
|
public ChangedFile(AbstractAsset asset, byte[] fileData) : this(fileData, asset.InternalTGI, asset.Package)
|
||||||
|
|
|
@ -8,6 +8,7 @@ using UnityEngine.UI;
|
||||||
using OpenTS2.Files;
|
using OpenTS2.Files;
|
||||||
using OpenTS2.Files.Formats.Reia;
|
using OpenTS2.Files.Formats.Reia;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace OpenTS2.Engine.Tests
|
namespace OpenTS2.Engine.Tests
|
||||||
{
|
{
|
||||||
|
@ -28,14 +29,16 @@ namespace OpenTS2.Engine.Tests
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
var streamFs = Filesystem.OpenRead(reiaPath);
|
var realPath = Filesystem.GetRealPath(reiaPath);
|
||||||
|
var streamFs = File.OpenRead(realPath);
|
||||||
reia = ReiaFile.Read(streamFs, stream);
|
reia = ReiaFile.Read(streamFs, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reload()
|
void Reload()
|
||||||
{
|
{
|
||||||
reia.Dispose();
|
reia.Dispose();
|
||||||
var streamFs = Filesystem.OpenRead(reiaPath);
|
var realPath = Filesystem.GetRealPath(reiaPath);
|
||||||
|
var streamFs = File.OpenRead(realPath);
|
||||||
reia = ReiaFile.Read(streamFs, stream);
|
reia = ReiaFile.Read(streamFs, stream);
|
||||||
reload = false;
|
reload = false;
|
||||||
frameCounter = 0f;
|
frameCounter = 0f;
|
||||||
|
|
|
@ -67,22 +67,6 @@ namespace OpenTS2.Files
|
||||||
{
|
{
|
||||||
var userPath = s_pathProvider.GetUserPath();
|
var userPath = s_pathProvider.GetUserPath();
|
||||||
var packageList = RemoveNeighborhoodAndCCPackagesFromList(GetPackagesInDirectory(userPath));
|
var packageList = RemoveNeighborhoodAndCCPackagesFromList(GetPackagesInDirectory(userPath));
|
||||||
/*
|
|
||||||
var collectionsPath = Path.Combine(userPath, "Collections");
|
|
||||||
var lockedBinsPath = Path.Combine(userPath, "LockedBins");
|
|
||||||
var lotCatalogPath = Path.Combine(userPath, "LotCatalog");
|
|
||||||
var petBreedsPath = Path.Combine(userPath, "PetBreeds");
|
|
||||||
var petCoatsPath = Path.Combine(userPath, "PetCoats");
|
|
||||||
var savedSimsPath = Path.Combine(userPath, "SavedSims");
|
|
||||||
var thumbnailsPath = Path.Combine(userPath, "Thumbnails");
|
|
||||||
var packageList = new List<string>();
|
|
||||||
packageList.AddRange(GetPackagesInDirectory(collectionsPath));
|
|
||||||
packageList.AddRange(GetPackagesInDirectory(lockedBinsPath));
|
|
||||||
packageList.AddRange(GetPackagesInDirectory(lotCatalogPath));
|
|
||||||
packageList.AddRange(GetPackagesInDirectory(petBreedsPath));
|
|
||||||
packageList.AddRange(GetPackagesInDirectory(petCoatsPath));
|
|
||||||
packageList.AddRange(GetPackagesInDirectory(savedSimsPath));
|
|
||||||
packageList.AddRange(GetPackagesInDirectory(thumbnailsPath));*/
|
|
||||||
return packageList;
|
return packageList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,28 +250,9 @@ namespace OpenTS2.Files
|
||||||
path = FileUtils.CleanPath(path);
|
path = FileUtils.CleanPath(path);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Opens a file for writing.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="path">Unparsed path</param>
|
|
||||||
/// <returns>A FileStream</returns>
|
|
||||||
public static FileStream OpenWrite(string path)
|
|
||||||
{
|
|
||||||
return File.OpenWrite(GetRealPath(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opens a file for reading.
|
/// Writes a byte array into a file, creating all necessary directories.
|
||||||
/// </summary>
|
|
||||||
/// <param name="path">Unparsed path</param>
|
|
||||||
/// <returns>A FileStream</returns>
|
|
||||||
public static FileStream OpenRead(string path)
|
|
||||||
{
|
|
||||||
return File.OpenRead(GetRealPath(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Writes a byte array into a file.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">Path to output file.</param>
|
/// <param name="path">Path to output file.</param>
|
||||||
/// <param name="bytes">Byte array to write.</param>
|
/// <param name="bytes">Byte array to write.</param>
|
||||||
|
@ -297,29 +262,18 @@ namespace OpenTS2.Files
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes a byte array into a file.
|
/// Writes a byte array into a file, creating all necessary directories.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">Path to output file.</param>
|
/// <param name="path">Path to output file.</param>
|
||||||
/// <param name="bytes">Byte array to write.</param>
|
/// <param name="bytes">Byte array to write.</param>
|
||||||
public static void Write(string path, byte[] bytes, int size)
|
public static void Write(string path, byte[] bytes, int size)
|
||||||
{
|
{
|
||||||
var realPath = GetRealPath(path);
|
var dir = Path.GetDirectoryName(path);
|
||||||
var dir = Path.GetDirectoryName(realPath);
|
|
||||||
if (!Directory.Exists(dir) && !string.IsNullOrEmpty(dir))
|
if (!Directory.Exists(dir) && !string.IsNullOrEmpty(dir))
|
||||||
Directory.CreateDirectory(dir);
|
Directory.CreateDirectory(dir);
|
||||||
var fStream = new FileStream(realPath, FileMode.Create, FileAccess.Write);
|
var fStream = new FileStream(path, FileMode.Create, FileAccess.Write);
|
||||||
fStream.Write(bytes, 0, size);
|
fStream.Write(bytes, 0, size);
|
||||||
fStream.Dispose();
|
fStream.Dispose();
|
||||||
//File.WriteAllBytes(realPath, bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deletes a file
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="path">Path to file to delete.</param>
|
|
||||||
public static void Delete(string path)
|
|
||||||
{
|
|
||||||
File.Delete(path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,7 +311,7 @@ namespace OpenTS2.Files.Formats.DBPF
|
||||||
{
|
{
|
||||||
_filePath = file;
|
_filePath = file;
|
||||||
GroupID = FileUtils.GroupHash(Path.GetFileNameWithoutExtension(file));
|
GroupID = FileUtils.GroupHash(Path.GetFileNameWithoutExtension(file));
|
||||||
var stream = Filesystem.OpenRead(file);
|
var stream = File.OpenRead(file);
|
||||||
Read(stream);
|
Read(stream);
|
||||||
_changes.Dirty = false;
|
_changes.Dirty = false;
|
||||||
}
|
}
|
||||||
|
@ -403,6 +403,7 @@ namespace OpenTS2.Files.Formats.DBPF
|
||||||
}
|
}
|
||||||
_compressionDIR = (DIRAsset)GetAssetByTGI(ResourceKey.DIR);
|
_compressionDIR = (DIRAsset)GetAssetByTGI(ResourceKey.DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write and clear all changes to FilePath.
|
/// Write and clear all changes to FilePath.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -412,7 +413,7 @@ namespace OpenTS2.Files.Formats.DBPF
|
||||||
{
|
{
|
||||||
Dispose();
|
Dispose();
|
||||||
Provider?.RemovePackage(this);
|
Provider?.RemovePackage(this);
|
||||||
Filesystem.Delete(FilePath);
|
File.Delete(FilePath);
|
||||||
Changes.Clear();
|
Changes.Clear();
|
||||||
_deleted = true;
|
_deleted = true;
|
||||||
return;
|
return;
|
||||||
|
@ -420,7 +421,7 @@ namespace OpenTS2.Files.Formats.DBPF
|
||||||
var data = Serialize();
|
var data = Serialize();
|
||||||
Dispose();
|
Dispose();
|
||||||
Filesystem.Write(FilePath, data);
|
Filesystem.Write(FilePath, data);
|
||||||
var stream = Filesystem.OpenRead(FilePath);
|
var stream = File.OpenRead(FilePath);
|
||||||
Read(stream);
|
Read(stream);
|
||||||
Changes.Clear();
|
Changes.Clear();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class ContentTest
|
||||||
stringSetData.Strings[Languages.USEnglish].Add(new StringValue(usString));
|
stringSetData.Strings[Languages.USEnglish].Add(new StringValue(usString));
|
||||||
var stringSet = new StringSetAsset(stringSetData);
|
var stringSet = new StringSetAsset(stringSetData);
|
||||||
|
|
||||||
// Test US Localisation String.
|
// Test US Localization String.
|
||||||
Assert.AreEqual(usString, stringSet.StringData.GetString(0, Languages.USEnglish));
|
Assert.AreEqual(usString, stringSet.StringData.GetString(0, Languages.USEnglish));
|
||||||
|
|
||||||
// Test fallback to US String when UK Language (or any other) is not present.
|
// Test fallback to US String when UK Language (or any other) is not present.
|
||||||
|
|
8
Assets/Tests/OpenTS2/Files.meta
Normal file
8
Assets/Tests/OpenTS2/Files.meta
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 07981c4d1f1b5a047bb25676ce625998
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
8
Assets/Tests/OpenTS2/Files/Formats.meta
Normal file
8
Assets/Tests/OpenTS2/Files/Formats.meta
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 54e831512dec5b64084bccde60202d5a
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
8
Assets/Tests/OpenTS2/Files/Formats/DBPF.meta
Normal file
8
Assets/Tests/OpenTS2/Files/Formats/DBPF.meta
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5f7409c616298d94c8f11c35a17154d9
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
36
Assets/Tests/OpenTS2/Files/Formats/DBPF/DBPFFileTest.cs
Normal file
36
Assets/Tests/OpenTS2/Files/Formats/DBPF/DBPFFileTest.cs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
using NUnit.Framework;
|
||||||
|
using OpenTS2.Files.Formats.DBPF;
|
||||||
|
using OpenTS2.Common;
|
||||||
|
using System.IO;
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
public class DPBFFileTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void DBPFFileSaveLoadTest()
|
||||||
|
{
|
||||||
|
var dummyTGI = new ResourceKey("dummyresource", GroupIDs.Local, 0x0);
|
||||||
|
var dummyResourceBytes = Encoding.ASCII.GetBytes("TestResource");
|
||||||
|
var packagePath = "TestFiles/TestPackage.package";
|
||||||
|
|
||||||
|
var package = new DBPFFile();
|
||||||
|
package.FilePath = packagePath;
|
||||||
|
Assert.IsTrue(package.Empty);
|
||||||
|
package.Changes.Set(dummyResourceBytes, dummyTGI, false);
|
||||||
|
Assert.IsTrue(package.Entries.Count == 1);
|
||||||
|
var data = package.GetItemByTGI(dummyTGI);
|
||||||
|
Assert.IsTrue(data == dummyResourceBytes);
|
||||||
|
package.WriteToFile();
|
||||||
|
package.Dispose();
|
||||||
|
|
||||||
|
var loadedPackage = new DBPFFile(packagePath);
|
||||||
|
Assert.IsTrue(package.Entries.Count == 1);
|
||||||
|
var dummyResource = loadedPackage.GetItemByTGI(dummyTGI);
|
||||||
|
Assert.IsTrue(Encoding.ASCII.GetString(dummyResource) == Encoding.ASCII.GetString(dummyResourceBytes));
|
||||||
|
loadedPackage.Dispose();
|
||||||
|
|
||||||
|
if (File.Exists(packagePath))
|
||||||
|
File.Delete(packagePath);
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Tests/OpenTS2/Files/Formats/DBPF/DBPFFileTest.cs.meta
Normal file
11
Assets/Tests/OpenTS2/Files/Formats/DBPF/DBPFFileTest.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f4d6b1a7a351a4048871fa7985b6dcfd
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in a new issue