Skip to content

Commit

Permalink
Removed old zip class
Browse files Browse the repository at this point in the history
Manipulating zip files is now a native part of the .NET framework. Removing this class (which was only used in one spot) allows us to remove a dependency.
  • Loading branch information
atruskie committed Dec 4, 2017
1 parent 4adc8d0 commit f3f4345
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 347 deletions.
2 changes: 2 additions & 0 deletions AudioAnalysis/AnalysisPrograms/AnalysisPrograms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@
<Reference Include="System.IO, Version=2.6.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.1.1.10\lib\net40\System.IO.dll</HintPath>
</Reference>
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net40\System.Net.Http.dll</HintPath>
Expand Down
11 changes: 8 additions & 3 deletions AudioAnalysis/AnalysisPrograms/FeltTemplate_Edit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using Acoustics.Shared.Extensions;
Expand Down Expand Up @@ -132,19 +133,23 @@ public static void Execute(Arguments arguments)
var filenames = new[]
{ iniPath, targetImagePath, binaryOpPath, targetPath, targetNoNoisePath, noisePath };
string biOutZipFile = outputDir + targetName + "_binaryTemplate.zip";
FileTools.ZipFiles(filenames, biOutZipFile);
//FileTools.ZipFiles(filenames, biOutZipFile);

filenames = new[]
{ iniPath, targetImagePath, trinaryOpPath, targetPath, targetNoNoisePath, noisePath };

string triOutZipFile = outputDir + targetName + "_trinaryTemplate.zip";
FileTools.ZipFiles(filenames, triOutZipFile);
//FileTools.ZipFiles(filenames, triOutZipFile);

filenames = new[]
{ iniPath, targetImagePath, sprOpPath, targetPath, targetNoNoisePath, noisePath };

string sprOutZipFile = outputDir + targetName + "_syntacticTemplate.zip";
FileTools.ZipFiles(filenames, sprOutZipFile);
//FileTools.ZipFiles(filenames, sprOutZipFile);

// Zipping files can be done by using standard .NET 4.6 System.IO.Compression
// however, this code hasn't been used in years and I've opted to just comment out the lines above
throw new NotImplementedException("Zipping template files intentionally broken");
}

Log.WriteLine("\n\n#################################### TEST THE EXTRACTED EVENT ON SOURCE FILE ##################################");
Expand Down
3 changes: 2 additions & 1 deletion AudioAnalysis/AnalysisPrograms/FeltTemplates_Use.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using Acoustics.Shared.Extensions;
Expand Down Expand Up @@ -121,7 +122,7 @@ public static void Execute(Arguments arguments)
if (zipPath.Length < 2) continue; // empty line

//i: get params file
FileTools.UnZip(arguments.Output.FullName, zipPath, true);
ZipFile.ExtractToDirectory(arguments.Output.FullName, zipPath);
string zipName = Path.GetFileNameWithoutExtension(zipPath);
string[] parts = zipName.Split('_');
string paramsPath = Path.Combine(arguments.Output.FullName, parts[0] + "_" + parts[1] + "_Params.txt");
Expand Down
173 changes: 0 additions & 173 deletions AudioAnalysis/TowseyLibrary/FileTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace TowseyLibrary
using System.Linq;
using System.Text;
using Acoustics.Shared.Extensions;
using ICSharpCode.SharpZipLib.Zip;

public static class FileTools
{
Expand Down Expand Up @@ -568,177 +567,5 @@ public static string UrlCombine(params string[] segments)
});
} // end of UrlCombine(params string[] segments)


// ############################################################################################################################################
// ########################################### FOLLOWING METHODS TO ZIP AND UNZIP FILES ######################################################
// ########################################### FIRST METOHD GIVES EXAMPLE CALLS ##############################################################


//static void Main(string[] args)
//{

// string dir = "C:\\SensorNetworks\\Templates\\Template_CURRAWONG1";
// string Dir2Compress = dir + "\\config_CURRAWONG1";
// string OutZipFile = Dir2Compress + ".zip";
// string Target = dir + "\\config_CURRAWONG2";

// //ZipDirectory(Dir2Compress, OutZipFile);
// ZipDirectoryRecursive(Dir2Compress, OutZipFile, true);
// UnZip(Target, OutZipFile, true);

// LoggedConsole.WriteLine("FINISHED");
// Console.ReadLine();

//} //end method Main()


/// <summary>
/// zips all files in passed directory.
/// Does NOT zip directories recursively.
/// </summary>
/// <param name="Dir2Compress"></param>
/// <param name="outZipFile"></param>
public static void ZipDirectory(string Dir2Compress, string outZipFile)
{
string[] filenames = Directory.GetFiles(Dir2Compress);
ZipFiles(filenames, outZipFile);
}

public static void ZipFiles(FileInfo[] filenames, string outZipFile)
{
ZipFiles(filenames.Select(fi => fi.FullName).ToArray(), outZipFile);
}

/// <summary>
/// zips all files in passed list of file names.
/// Does NOT zip directories recursively
/// </summary>
/// <param name="filenames"></param>
/// <param name="outZipFile"></param>
public static void ZipFiles(string[] filenames, string outZipFile)
{

try
{
// 'using' statements gaurantee the stream is closed properly which is a big source
// of problems otherwise. Its exception safe as well which is great.
using (ZipOutputStream s = new ZipOutputStream(File.Create(outZipFile)))
{

s.SetLevel(9); // 0 - store only to 9 - means best compression

byte[] buffer = new byte[4096];

foreach (string file in filenames)
{

// Using Path.GetFileName() makes the result compatible with XP as the resulting path is not absolute.
LoggedConsole.WriteLine("file=" + file);
ZipEntry entry = new ZipEntry(Path.GetFileName(file));

// Setup the entry data as required.
// Crc and size are handled by the library for seakable streams so no need to do them here.

// Could also use the last write time or similar for the file.
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);

using (FileStream fs = File.OpenRead(file))
{

// Using a fixed size buffer here makes no noticeable difference for output
// but keeps a lid on memory usage.
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}

// Finish/Close arent needed strictly as the using statement does this automatically
// Finish is important to ensure trailing information for a Zip file is appended.
// Without this the created file would be invalid.
s.Finish();

// Close is important to wrap things up and unlock the file.
s.Close();
}

//check the zip file was formed
if (File.Exists(outZipFile))
{
FileInfo fi = new FileInfo(outZipFile);
LoggedConsole.WriteLine("Zipped file has been created at " + fi.FullName);
}
else LoggedConsole.WriteLine("Zipped File WAS NOT CREATED.");
}
catch (Exception ex)
{
LoggedConsole.WriteLine("Exception during processing {0}", ex);

// No need to rethrow the exception as for our purposes its handled.
}

} //end method ZipDirectory()


public static void ZipDirectoryRecursive(string Dir2Compress, string OutZipFile, bool verbose)
{
string fileFilter = null;
string dirFilter = null;
//bool restoreDates = false;
//bool restoreAttributes = false;
bool recurse = true;
//bool createEmptyDirs = false;

//bool progress = false;
TimeSpan interval = TimeSpan.FromSeconds(1);
FastZipEvents events = null;

if (verbose)
{
//events = new FastZipEvents();
//events.ProcessDirectory = new ProcessDirectoryHandler(ProcessDirectory);
//events.ProcessFile = new ProcessFileHandler(ProcessFile);

//if (progress)
//{
// events.Progress = new ProgressHandler(ShowProgress);
// events.ProgressInterval = interval;
//}
}

FastZip fastZip = new FastZip(events);
//fastZip.CreateEmptyDirectories = createEmptyDirs;
//fastZip.RestoreAttributesOnExtract = restoreAttributes;
//fastZip.RestoreDateTimeOnExtract = restoreDates;
fastZip.CreateZip(OutZipFile, Dir2Compress, recurse, fileFilter, dirFilter);

}


public static void UnZip(string targetDir, string zipFN, bool verbose)
{
bool restoreDates = false;
bool restoreAttributes = false;
bool recurse = true;
bool createEmptyDirs = true;
string fileFilter = null;
string dirFilter = null;

FastZip.Overwrite overwrite = FastZip.Overwrite.Always;
FastZip.ConfirmOverwriteDelegate confirmOverwrite = null;
FastZipEvents events = null;

FastZip fastZip = new FastZip(events);
fastZip.CreateEmptyDirectories = createEmptyDirs;
fastZip.RestoreAttributesOnExtract = restoreAttributes;
fastZip.RestoreDateTimeOnExtract = restoreDates;
fastZip.ExtractZip(zipFN, targetDir, overwrite, confirmOverwrite, fileFilter, dirFilter, recurse);

}

}// end class
}
5 changes: 0 additions & 5 deletions AudioAnalysis/TowseyLibrary/TowseyLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,6 @@
<Reference Include="CsvHelper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8c4959082be5c823, processorArchitecture=MSIL">
<HintPath>..\packages\CsvHelper.2.16.2.0\lib\net45\CsvHelper.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Extra Assemblies\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -317,7 +313,6 @@
<Compile Include="TextUtilities.cs" />
<Compile Include="FunctionalTests.cs" />
<Compile Include="WaveletPacketDecomposition.cs" />
<Compile Include="ZipUnzip.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
Expand Down
Loading

0 comments on commit f3f4345

Please sign in to comment.