This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from modio/v2.3.2-dev
V2.3.2
- Loading branch information
Showing
22 changed files
with
585 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace ModIO | ||
{ | ||
/// <summary>Defines the static interface for the compression operations.</summary> | ||
public static class CompressionModule | ||
{ | ||
// ---------[ Constants ]--------- | ||
/// <summary>Compression implementation to use.</summary> | ||
public static readonly ICompressionImpl IMPLEMENTATION; | ||
|
||
// ---------[ Initialization ]--------- | ||
/// <summary>Loads the compression implementation.</summary> | ||
static CompressionModule() | ||
{ | ||
CompressionModule.IMPLEMENTATION = new DotNetZipCompressionImpl(); | ||
} | ||
|
||
// ---------[ Interface ]--------- | ||
/// <summary>Extracts the contents of an archive.</summary> | ||
public static bool ExtractAll(string archivePath, string targetDirectory) | ||
{ | ||
return CompressionModule.IMPLEMENTATION.ExtractAll(archivePath, targetDirectory); | ||
} | ||
|
||
/// <summary>Compresses the contents of a file collection into an output archive.</summary> | ||
public static bool CompressFileCollection(string rootDirectory, | ||
IEnumerable<string> filePathCollection, | ||
string targetFilePath) | ||
{ | ||
return CompressionModule.IMPLEMENTATION.CompressFileCollection(rootDirectory, filePathCollection, targetFilePath); | ||
} | ||
|
||
/// <summary>Compresses a single file into an output archive.</summary> | ||
public static bool CompressFile(string filePath, string targetFilePath) | ||
{ | ||
return CompressionModule.IMPLEMENTATION.CompressFile(filePath, targetFilePath); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
using System.Collections.Generic; | ||
|
||
using Exception = System.Exception; | ||
using Debug = UnityEngine.Debug; | ||
using Path = System.IO.Path; | ||
|
||
namespace ModIO | ||
{ | ||
/// <summary>A wrapper for the DotNetZip library that matches the ICompressionImpl interface.</summary> | ||
public class DotNetZipCompressionImpl : ICompressionImpl | ||
{ | ||
// ---------[ Interface ]--------- | ||
/// <summary>Extracts the contents of an archive.</summary> | ||
public bool ExtractAll(string archivePath, string targetDirectory) | ||
{ | ||
// early outs | ||
if(string.IsNullOrEmpty(archivePath)) | ||
{ | ||
Debug.LogWarning("[mod.io] Unable to extract archive to target directory." | ||
+ "\narchivePath is NULL or EMPTY."); | ||
return false; | ||
} | ||
if(string.IsNullOrEmpty(targetDirectory)) | ||
{ | ||
Debug.LogWarning("[mod.io] Unable to extract archive to target directory." | ||
+ "\ntargetDirectory is NULL or EMPTY."); | ||
return false; | ||
} | ||
|
||
// Extract | ||
bool success = false; | ||
|
||
try | ||
{ | ||
using (var zip = Ionic.Zip.ZipFile.Read(archivePath)) | ||
{ | ||
zip.ExtractAll(targetDirectory); | ||
|
||
success = true; | ||
} | ||
} | ||
catch(Exception e) | ||
{ | ||
Debug.LogWarning("[mod.io] Unable to extract archive to target directory." | ||
+ "\nArchive: " + archivePath | ||
+ "\nTarget: " + targetDirectory | ||
+ "\n\n" | ||
+ Utility.GenerateExceptionDebugString(e)); | ||
} | ||
|
||
return success; | ||
} | ||
|
||
/// <summary>Compresses the contents of a file collection into a new output archive.</summary> | ||
public bool CompressFileCollection(string rootDirectory, | ||
IEnumerable<string> filePathCollection, | ||
string targetFilePath) | ||
{ | ||
// early outs | ||
if(filePathCollection == null) | ||
{ | ||
Debug.LogWarning("[mod.io] Unable to compress file collection to archive." | ||
+ "\nfilePathCollection is NULL."); | ||
return false; | ||
} | ||
if(string.IsNullOrEmpty(targetFilePath)) | ||
{ | ||
Debug.LogWarning("[mod.io] Unable to compress file collection to archive." | ||
+ "\ntargetFilePath is NULL or EMPTY."); | ||
return false; | ||
} | ||
|
||
// compress | ||
if(string.IsNullOrEmpty(rootDirectory)) | ||
{ | ||
rootDirectory = string.Empty; | ||
} | ||
|
||
bool success = false; | ||
string lastFilePath = string.Empty; | ||
|
||
try | ||
{ | ||
using(var zip = new Ionic.Zip.ZipFile()) | ||
{ | ||
foreach(string filePath in filePathCollection) | ||
{ | ||
lastFilePath = filePath; | ||
|
||
string relativeFilePath = filePath.Substring(rootDirectory.Length); | ||
string relativeDirectory = Path.GetDirectoryName(relativeFilePath); | ||
|
||
zip.AddFile(filePath, relativeDirectory); | ||
} | ||
|
||
zip.Save(targetFilePath); | ||
|
||
success = true; | ||
} | ||
} | ||
catch(Exception e) | ||
{ | ||
Debug.LogWarning("[mod.io] Unable to compress file collection to archive." | ||
+ "\nLast Attempted File: " + lastFilePath | ||
+ "\nOutput: " + targetFilePath | ||
+ "\n\n" | ||
+ Utility.GenerateExceptionDebugString(e)); | ||
} | ||
|
||
return success; | ||
} | ||
|
||
/// <summary>Compresses a single file into a new output archive.</summary> | ||
public bool CompressFile(string filePath, string targetFilePath) | ||
{ | ||
// early outs | ||
if(string.IsNullOrEmpty(filePath)) | ||
{ | ||
Debug.LogWarning("[mod.io] Unable to compress file collection to archive." | ||
+ "\nfilePath is NULL or EMPTY."); | ||
return false; | ||
} | ||
if(string.IsNullOrEmpty(targetFilePath)) | ||
{ | ||
Debug.LogWarning("[mod.io] Unable to compress file collection to archive." | ||
+ "\ntargetFilePath is NULL or EMPTY."); | ||
return false; | ||
} | ||
|
||
// compress | ||
bool success = false; | ||
|
||
try | ||
{ | ||
using(var zip = new Ionic.Zip.ZipFile()) | ||
{ | ||
zip.AddFile(filePath, ""); | ||
zip.Save(targetFilePath); | ||
success = true; | ||
} | ||
} | ||
catch(Exception e) | ||
{ | ||
Debug.LogWarning("[mod.io] Unable to compress file to archive." | ||
+ "\nFile: " + filePath | ||
+ "\nOutput: " + targetFilePath | ||
+ "\n\n" | ||
+ Utility.GenerateExceptionDebugString(e)); | ||
} | ||
|
||
return success; | ||
} | ||
} | ||
} |
Oops, something went wrong.