Skip to content

Commit 29249f0

Browse files
Addition of String Input Mode
-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.
1 parent 8aed6bc commit 29249f0

File tree

6 files changed

+59
-42
lines changed

6 files changed

+59
-42
lines changed

PeepsCompress/PeepsCompress/Abstract Classes/Compression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace PeepsCompress
55
public abstract class Compression
66
{
77
public abstract byte[] compress(byte[] file, int offset);
8-
public abstract byte[] compressInitialization(string path);
8+
public abstract byte[] compressInitialization(string path, bool fileInputMode);
99
public abstract byte[] decompress(BinaryReader br, int offset, FileStream inputFile);
1010
public abstract byte[] decompressInitialization(string path);
1111

PeepsCompress/PeepsCompress/Algorithm Classes/MIO0.cs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,6 @@ public override byte[] decompressInitialization(string path)
1919
int offset = mio0File.IndexOf("MIO0");
2020
inputFile.Position = offset;
2121

22-
/*
23-
if (file.Length == mio0File.Length)
24-
{
25-
MessageBox.Show("String and file same size");
26-
}
27-
else
28-
{
29-
MessageBox.Show("Stop: Not the same size. This will not work.");
30-
}
31-
32-
33-
while (mio0File.Contains("MIO0"))
34-
{
35-
int offset = mio0File.IndexOf("MIO0");
36-
inputFile.Seek(offset, SeekOrigin.Begin);
37-
38-
byte[] decompressedFile = decompress(br, offset, inputFile);
39-
mio0File = Encoding.ASCII.GetString(file);
40-
}
41-
*/
42-
4322
//decompress(file);
4423

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

139118

140-
public override byte[] compressInitialization(string path)
119+
public override byte[] compressInitialization(string path, bool fileInputMode)
141120
{
142-
FileStream inputFile = File.Open(path, FileMode.Open);
143-
BigEndianBinaryReader br = new BigEndianBinaryReader(inputFile);
144-
byte[] file = br.ReadBytes((int)inputFile.Length);
121+
if (fileInputMode)
122+
{
123+
FileStream inputFile = File.Open(path, FileMode.Open);
124+
BigEndianBinaryReader br = new BigEndianBinaryReader(inputFile);
125+
byte[] file = br.ReadBytes((int)inputFile.Length);
145126

146-
return compress(file, 0);
127+
return compress(file, 0);
128+
}
129+
else
130+
{
131+
byte[] stringToFile = Encoding.ASCII.GetBytes(path);
132+
133+
return compress(stringToFile, 0);
134+
}
147135
}
148136

149137
public override byte[] compress(byte[] file, int offset)

PeepsCompress/PeepsCompress/Algorithm Classes/YAY0.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,22 @@ public override byte[] decompress(BinaryReader br, int offset, FileStream inputF
298298
}
299299
}
300300

301-
public override byte[] compressInitialization(string path)
301+
public override byte[] compressInitialization(string path, bool fileInputMode)
302302
{
303-
FileStream inputFile = File.Open(path, FileMode.Open);
304-
BigEndianBinaryReader br = new BigEndianBinaryReader(inputFile);
305-
byte[] file = br.ReadBytes((int)inputFile.Length);
303+
if (fileInputMode)
304+
{
305+
FileStream inputFile = File.Open(path, FileMode.Open);
306+
BigEndianBinaryReader br = new BigEndianBinaryReader(inputFile);
307+
byte[] file = br.ReadBytes((int)inputFile.Length);
306308

307-
return compress(file, 0);
309+
return compress(file, 0);
310+
}
311+
else
312+
{
313+
byte[] stringToFile = Encoding.ASCII.GetBytes(path);
314+
315+
return compress(stringToFile, 0);
316+
}
308317
}
309318

310319
public override byte[] decompressInitialization(string path)

PeepsCompress/PeepsCompress/Algorithm Classes/YAZ0.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,22 @@ public override byte[] decompress(BinaryReader br, int offset, FileStream inputF
245245

246246
}
247247

248-
public override byte[] compressInitialization(string path)
248+
public override byte[] compressInitialization(string path, bool fileInputMode)
249249
{
250-
FileStream inputFile = File.Open(path, FileMode.Open);
251-
BigEndianBinaryReader br = new BigEndianBinaryReader(inputFile);
252-
byte[] file = br.ReadBytes((int)inputFile.Length);
250+
if (fileInputMode)
251+
{
252+
FileStream inputFile = File.Open(path, FileMode.Open);
253+
BigEndianBinaryReader br = new BigEndianBinaryReader(inputFile);
254+
byte[] file = br.ReadBytes((int)inputFile.Length);
253255

254-
return compress(file, 0);
256+
return compress(file, 0);
257+
}
258+
else
259+
{
260+
byte[] stringToFile = Encoding.ASCII.GetBytes(path);
261+
262+
return compress(stringToFile, 0);
263+
}
255264
}
256265
public override byte[] decompressInitialization(string path)
257266
{

PeepsCompress/PeepsCompress/MainGUI.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PeepsCompress/PeepsCompress/MainGUI.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
using System;
3-
using System.Text;
43
using System.Windows.Forms;
54
using System.IO;
65

@@ -18,9 +17,21 @@ public string returnFilePath()
1817
return filePathTextBox.Text;
1918
}
2019

20+
public bool checkTextInput()
21+
{
22+
if(inputMethodComboBox.SelectedIndex == 1 && returnFilePath() != "")
23+
{
24+
return true;
25+
}
26+
else
27+
{
28+
return false;
29+
}
30+
}
31+
2132
private void beginButton_Click(object sender, EventArgs e)
2233
{
23-
if (File.Exists(returnFilePath())) //TODO: Change this, it prevents string input mode.
34+
if (File.Exists(returnFilePath()) || checkTextInput())
2435
{
2536

2637
Compression algorithm;
@@ -56,7 +67,7 @@ private void beginButton_Click(object sender, EventArgs e)
5667
if (inputMethodComboBox.SelectedIndex == 0)
5768
{
5869
//file input
59-
byte[] compressedFile = algorithm.compressInitialization(returnFilePath());
70+
byte[] compressedFile = algorithm.compressInitialization(returnFilePath(), true);
6071

6172

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

0 commit comments

Comments
 (0)