aboutsummaryrefslogtreecommitdiff
path: root/CST 126/Homework2/main.cpp
blob: 82a2d32d8c2ce116a0e453e9adc043d826815bdd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//Name:Reece Warner
//Date:4/24/24
//Assignment:Homework2
#include "Base64Conversion.hpp"

constexpr short ARG_COUNT = 4;

bool Worker();
bool Worker(char** argv);

int main(const int argc, char* argv[])
{
	char* buffer = nullptr;
	char* MyEncodedCharArray = nullptr;
	bool success = false;
	const size_t size = SizeOfFile("randomtext.txt");
	buffer = new char[1];

	buffer = ReadFileAsBinary("randomtext.txt", buffer, size);

	MyEncodedCharArray = Base64Encode(buffer, size);

	success = WriteFileFromBinary(size, "destination_file.txt", buffer);
	delete[] buffer;
	
	//if (argc == ARG_COUNT)
	//{
	//	Worker(argv);
	//}
	//else
	//{
	//	//run other version!
	//}




	return Worker();		//can be used to trigger error controls
}


bool Worker()
{
	char option = 'e';

	switch (option)
	{
	case 'e':
		//file reading binary
		//encoding
		//file writing text
		return true;
	case 'd':
		//file reading text
		//decoding work
		//file writing binary
		return true;
	default:
		std::cerr << "Error, invalid command option\n" <<
			"Valid commands:\n" <<
			"\t -e source_file.exe destination_file.exe" <<
			"\tEncodes file in source to text in destination txt file.\n\n" <<
			"\t-d source_file.text destination_file.exe" <<
			"\tDecodes text in source file into the destination file.\n\n";
		return false;
	}

	return false;
}

bool Worker(char** argv)
{
	const char* arg1 = argv[1];//-e or -d
	const char* arg2 = argv[2];
	const char* arg3 = argv[3];
	char* buffer = nullptr;
	bool success = false;
	char* MyEncodedCharArray = nullptr;
	const size_t size = SizeOfFile(arg2);
	const char option = arg1[1];

	switch (option)
	{
	case 'e':
		//filereading binary
		buffer = new char[size];
		
		buffer = ReadFileAsBinary(arg2, buffer, size);
		
		MyEncodedCharArray = Base64Encode(buffer, size);

		success = WriteFileFromBinary(size, arg3, buffer);
		delete[] buffer;


		return success;
	case 'd':
		//file readingtext
		//decoding work
		//file writing binary
		return true;
	default:
		std::cerr << "Error, invalid command option\n" <<
			"Valid commands:\n" <<
			"\t -e source_file.exe destination_file.exe" <<
			"\tEncodes file in source to text in destination txt file.\n\n" <<
			"\t-d source_file.text destination_file.exe" <<
			"\tDecodes text in source file into the destination file.\n\n";
		return false;
	}
}