This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
816 additions
and
161 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> | ||
</configuration> |
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,128 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Data; | ||
using System.Diagnostics; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using csharp_prs; | ||
|
||
namespace csharp_prs_GUI | ||
{ | ||
public partial class MainForm : Form | ||
{ | ||
// Name of the directory relative to application directory to which all files are output. | ||
public const string TempDirectoryName = "temp-output"; | ||
|
||
public MainForm() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
/* | ||
----------- | ||
Drag Events | ||
----------- | ||
*/ | ||
|
||
/* | ||
Change Mouse Cursor & Target Drop Effect on Drag Enter with Files | ||
*/ | ||
private void btn_CompressDragDrop_DragEnter(object sender, DragEventArgs e) | ||
{ | ||
if (e.Data.GetDataPresent(DataFormats.FileDrop)) | ||
e.Effect = DragDropEffects.Copy; | ||
} | ||
|
||
private void btn_DecompressDragDrop_DragEnter(object sender, DragEventArgs e) | ||
{ | ||
if (e.Data.GetDataPresent(DataFormats.FileDrop)) | ||
e.Effect = DragDropEffects.Copy; | ||
} | ||
|
||
|
||
/* | ||
Process each file in a DragDrop operation. | ||
*/ | ||
private void btn_CompressDragDrop_DragDrop(object sender, DragEventArgs e) | ||
{ | ||
// Get files dropped onto button and process them. | ||
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); | ||
PrepareOutputFolder(); | ||
|
||
int searchBufferSize = (int)nud_SearchBufferSize.Value; | ||
ParallelOptions options = new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }; | ||
Parallel.ForEach(files, file => | ||
{ | ||
byte[] decompressedFile = File.ReadAllBytes(file); | ||
byte[] compressedFile = Prs.Compress(ref decompressedFile, searchBufferSize); | ||
|
||
string fileName = Path.GetFileName(file); | ||
File.WriteAllBytes($"{TempDirectoryName}\\{fileName}", compressedFile); | ||
}); | ||
|
||
// Open directory | ||
Process.Start(TempDirectoryName); | ||
} | ||
|
||
private void btn_DecompressDragDrop_DragDrop(object sender, DragEventArgs e) | ||
{ | ||
// Get files dropped onto button and process them. | ||
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); | ||
PrepareOutputFolder(); | ||
|
||
ParallelOptions options = new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }; | ||
Parallel.ForEach(files, file => | ||
{ | ||
byte[] compressedFile = File.ReadAllBytes(file); | ||
byte[] decompressedFile = Prs.Decompress(ref compressedFile); | ||
|
||
string fileName = Path.GetFileName(file); | ||
File.WriteAllBytes($"{TempDirectoryName}\\{fileName}", decompressedFile); | ||
}); | ||
|
||
// Open directory | ||
Process.Start(TempDirectoryName); | ||
} | ||
|
||
/* | ||
---------------------------- | ||
Compress/Decompress Routines | ||
---------------------------- | ||
*/ | ||
|
||
public void PrepareOutputFolder() | ||
{ | ||
if (! Directory.Exists(TempDirectoryName)) | ||
Directory.CreateDirectory(TempDirectoryName); | ||
else | ||
ClearDirectory(new DirectoryInfo(TempDirectoryName)); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Removes all files from a specific directory and subdirectories. | ||
/// </summary> | ||
public static void ClearDirectory(DirectoryInfo directory) | ||
{ | ||
foreach (FileInfo file in directory.GetFiles()) | ||
file.Delete(); | ||
|
||
foreach (DirectoryInfo subDirectory in directory.GetDirectories()) | ||
subDirectory.Delete(true); | ||
} | ||
|
||
/// <summary> | ||
/// Cleanup our temp folder. | ||
/// </summary> | ||
private void MainForm_FormClosed(object sender, FormClosedEventArgs e) | ||
{ | ||
if (Directory.Exists(TempDirectoryName)) | ||
new DirectoryInfo(TempDirectoryName).Delete(true); | ||
} | ||
} | ||
} |
Oops, something went wrong.