Skip to content

Commit

Permalink
Addition of String Input Mode
Browse files Browse the repository at this point in the history
-Finished addition of string input mode to allow users to compress text
written directly into the text box.

-Additionally the version number has been updated from 0.0 to 0.1 in
preparation for the first public release.
  • Loading branch information
Daniel-McCarthy committed May 14, 2017
1 parent 8aed6bc commit 29249f0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace PeepsCompress
public abstract class Compression
{
public abstract byte[] compress(byte[] file, int offset);
public abstract byte[] compressInitialization(string path);
public abstract byte[] compressInitialization(string path, bool fileInputMode);
public abstract byte[] decompress(BinaryReader br, int offset, FileStream inputFile);
public abstract byte[] decompressInitialization(string path);

Expand Down
40 changes: 14 additions & 26 deletions PeepsCompress/PeepsCompress/Algorithm Classes/MIO0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,6 @@ public override byte[] decompressInitialization(string path)
int offset = mio0File.IndexOf("MIO0");
inputFile.Position = offset;

/*
if (file.Length == mio0File.Length)
{
MessageBox.Show("String and file same size");
}
else
{
MessageBox.Show("Stop: Not the same size. This will not work.");
}
while (mio0File.Contains("MIO0"))
{
int offset = mio0File.IndexOf("MIO0");
inputFile.Seek(offset, SeekOrigin.Begin);
byte[] decompressedFile = decompress(br, offset, inputFile);
mio0File = Encoding.ASCII.GetString(file);
}
*/

//decompress(file);

return decompress(br, offset, inputFile);
Expand Down Expand Up @@ -137,13 +116,22 @@ public override byte[] decompress(BinaryReader br, int offset, FileStream inputF
}


public override byte[] compressInitialization(string path)
public override byte[] compressInitialization(string path, bool fileInputMode)
{
FileStream inputFile = File.Open(path, FileMode.Open);
BigEndianBinaryReader br = new BigEndianBinaryReader(inputFile);
byte[] file = br.ReadBytes((int)inputFile.Length);
if (fileInputMode)
{
FileStream inputFile = File.Open(path, FileMode.Open);
BigEndianBinaryReader br = new BigEndianBinaryReader(inputFile);
byte[] file = br.ReadBytes((int)inputFile.Length);

return compress(file, 0);
return compress(file, 0);
}
else
{
byte[] stringToFile = Encoding.ASCII.GetBytes(path);

return compress(stringToFile, 0);
}
}

public override byte[] compress(byte[] file, int offset)
Expand Down
19 changes: 14 additions & 5 deletions PeepsCompress/PeepsCompress/Algorithm Classes/YAY0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,22 @@ public override byte[] decompress(BinaryReader br, int offset, FileStream inputF
}
}

public override byte[] compressInitialization(string path)
public override byte[] compressInitialization(string path, bool fileInputMode)
{
FileStream inputFile = File.Open(path, FileMode.Open);
BigEndianBinaryReader br = new BigEndianBinaryReader(inputFile);
byte[] file = br.ReadBytes((int)inputFile.Length);
if (fileInputMode)
{
FileStream inputFile = File.Open(path, FileMode.Open);
BigEndianBinaryReader br = new BigEndianBinaryReader(inputFile);
byte[] file = br.ReadBytes((int)inputFile.Length);

return compress(file, 0);
return compress(file, 0);
}
else
{
byte[] stringToFile = Encoding.ASCII.GetBytes(path);

return compress(stringToFile, 0);
}
}

public override byte[] decompressInitialization(string path)
Expand Down
19 changes: 14 additions & 5 deletions PeepsCompress/PeepsCompress/Algorithm Classes/YAZ0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,22 @@ public override byte[] decompress(BinaryReader br, int offset, FileStream inputF

}

public override byte[] compressInitialization(string path)
public override byte[] compressInitialization(string path, bool fileInputMode)
{
FileStream inputFile = File.Open(path, FileMode.Open);
BigEndianBinaryReader br = new BigEndianBinaryReader(inputFile);
byte[] file = br.ReadBytes((int)inputFile.Length);
if (fileInputMode)
{
FileStream inputFile = File.Open(path, FileMode.Open);
BigEndianBinaryReader br = new BigEndianBinaryReader(inputFile);
byte[] file = br.ReadBytes((int)inputFile.Length);

return compress(file, 0);
return compress(file, 0);
}
else
{
byte[] stringToFile = Encoding.ASCII.GetBytes(path);

return compress(stringToFile, 0);
}
}
public override byte[] decompressInitialization(string path)
{
Expand Down
2 changes: 1 addition & 1 deletion PeepsCompress/PeepsCompress/MainGUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions PeepsCompress/PeepsCompress/MainGUI.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

using System;
using System.Text;
using System.Windows.Forms;
using System.IO;

Expand All @@ -18,9 +17,21 @@ public string returnFilePath()
return filePathTextBox.Text;
}

public bool checkTextInput()
{
if(inputMethodComboBox.SelectedIndex == 1 && returnFilePath() != "")
{
return true;
}
else
{
return false;
}
}

private void beginButton_Click(object sender, EventArgs e)
{
if (File.Exists(returnFilePath())) //TODO: Change this, it prevents string input mode.
if (File.Exists(returnFilePath()) || checkTextInput())
{

Compression algorithm;
Expand Down Expand Up @@ -56,7 +67,7 @@ private void beginButton_Click(object sender, EventArgs e)
if (inputMethodComboBox.SelectedIndex == 0)
{
//file input
byte[] compressedFile = algorithm.compressInitialization(returnFilePath());
byte[] compressedFile = algorithm.compressInitialization(returnFilePath(), true);


if (saveFileDialog1.ShowDialog() == DialogResult.OK)
Expand All @@ -79,7 +90,7 @@ private void beginButton_Click(object sender, EventArgs e)
else
{
//string input
byte[] compressedFile = algorithm.compress(Encoding.ASCII.GetBytes(filePathTextBox.Text), 0);//"How much wood would a woodchuck chuck if a woodchuck could chuck wood?"), 0);
byte[] compressedFile = algorithm.compressInitialization(returnFilePath(), false);
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
try
Expand Down

0 comments on commit 29249f0

Please sign in to comment.