diff options
| author | rPatrickWarner <[email protected]> | 2024-04-27 12:57:15 -0700 |
|---|---|---|
| committer | rPatrickWarner <[email protected]> | 2024-04-27 12:57:15 -0700 |
| commit | b7688d74869d4606913f5ff197c19183d0ef0aff (patch) | |
| tree | 467a6c77bb2d04aa8239fe4f8766b93ed1178084 /CST 126/Homework2 | |
| parent | init (diff) | |
| download | homework-1-reecepwarner-b7688d74869d4606913f5ff197c19183d0ef0aff.tar.xz homework-1-reecepwarner-b7688d74869d4606913f5ff197c19183d0ef0aff.zip | |
Added binary file reading function
Diffstat (limited to 'CST 126/Homework2')
| -rw-r--r-- | CST 126/Homework2/Base64Conversion.hpp | 7 | ||||
| -rw-r--r-- | CST 126/Homework2/Base64Helper.hpp | 58 | ||||
| -rw-r--r-- | CST 126/Homework2/Homework2.vcxproj | 10 | ||||
| -rw-r--r-- | CST 126/Homework2/Homework2.vcxproj.filters | 16 | ||||
| -rw-r--r-- | CST 126/Homework2/destination_file.txt | 0 | ||||
| -rw-r--r-- | CST 126/Homework2/main.cpp | 79 |
6 files changed, 166 insertions, 4 deletions
diff --git a/CST 126/Homework2/Base64Conversion.hpp b/CST 126/Homework2/Base64Conversion.hpp new file mode 100644 index 0000000..3a87f70 --- /dev/null +++ b/CST 126/Homework2/Base64Conversion.hpp @@ -0,0 +1,7 @@ +#ifndef BASE64_CONVERSION_HPP +#define BASE64_CONVERSION_HPP +#include "Base64Helper.hpp" + + + +#endif
\ No newline at end of file diff --git a/CST 126/Homework2/Base64Helper.hpp b/CST 126/Homework2/Base64Helper.hpp new file mode 100644 index 0000000..d3e9a5f --- /dev/null +++ b/CST 126/Homework2/Base64Helper.hpp @@ -0,0 +1,58 @@ +#ifndef BASE64_HELPER_HPP +#define BASE64_HELPER_HPP +#include <fstream> +#include <iostream> + +inline char* ReadTextFromFile(const char* fileName, char* buffer) +{ + return buffer; +} + +inline char* ReadFileAsBinary(const char* fileName, char* buffer) +{ + try + { + //open fstream in input mode, with binary mode + + std::fstream File(fileName, std::ios::in | std::ios::binary); + + if (File.fail()) + { + std::cerr << "Could not open file for binary input: " << fileName; + return buffer; + } + File.seekg(0, std::ios::end); + std::streamsize size = File.tellg(); + File.seekg(0, std::ios::beg); + + delete[] buffer; + buffer = nullptr; + + + buffer = new char[size]; + File.read(buffer, size); + File.close(); + return buffer; + } + catch (const std::exception& ex) + { + std::cerr << "Exception during binary file input. " << fileName + << " was not successfully streamed to binary. " << + ex.what(); + return buffer; + } +} + +inline bool WriteFileFromBinary(const char* fileName, const char* buffer) +{ + return false; +} + +inline bool WriteTextToFile(const char* fileName, const char* fileContents) +{ + return false; +} + + + +#endif
\ No newline at end of file diff --git a/CST 126/Homework2/Homework2.vcxproj b/CST 126/Homework2/Homework2.vcxproj index 665cc94..978f773 100644 --- a/CST 126/Homework2/Homework2.vcxproj +++ b/CST 126/Homework2/Homework2.vcxproj @@ -129,6 +129,16 @@ <ItemGroup> <ClCompile Include="main.cpp" /> </ItemGroup> + <ItemGroup> + <ClInclude Include="Base64Conversion.hpp" /> + <ClInclude Include="Base64Helper.hpp" /> + </ItemGroup> + <ItemGroup> + <Text Include="destination_file.txt" /> + </ItemGroup> + <ItemGroup> + <None Include="..\..\..\..\..\..\Downloads\FindingPi.exe" /> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> diff --git a/CST 126/Homework2/Homework2.vcxproj.filters b/CST 126/Homework2/Homework2.vcxproj.filters index ce0c35c..22989db 100644 --- a/CST 126/Homework2/Homework2.vcxproj.filters +++ b/CST 126/Homework2/Homework2.vcxproj.filters @@ -19,4 +19,20 @@ <Filter>Source Files</Filter> </ClCompile> </ItemGroup> + <ItemGroup> + <ClInclude Include="Base64Helper.hpp"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="Base64Conversion.hpp"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> + <ItemGroup> + <Text Include="destination_file.txt" /> + </ItemGroup> + <ItemGroup> + <None Include="..\..\..\..\..\..\Downloads\FindingPi.exe"> + <Filter>Source Files</Filter> + </None> + </ItemGroup> </Project>
\ No newline at end of file diff --git a/CST 126/Homework2/destination_file.txt b/CST 126/Homework2/destination_file.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/CST 126/Homework2/destination_file.txt diff --git a/CST 126/Homework2/main.cpp b/CST 126/Homework2/main.cpp index 1d71629..c434ba9 100644 --- a/CST 126/Homework2/main.cpp +++ b/CST 126/Homework2/main.cpp @@ -1,19 +1,90 @@ //Name:Reece Warner //Date:4/24/24 //Assignment:Homework2 +#include "Base64Conversion.hpp" -#include <fstream> -#include <iostream> +constexpr short ARG_COUNT = 4; +bool Worker(); +bool Worker(char** argv); -int main(int argc, char* argv) +int main(const int argc, char* argv[]) { + if (argc == ARG_COUNT) + { + //run commandline version + 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]; + const char option = arg1[1]; - return 0; + switch (option) + { + case 'e': + //filereading binary + char* buffer = new char[1]; + buffer = ReadFileAsBinary(arg2, buffer); + //encoding + //file writing text + delete[] buffer; + return true; + 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; + } }
\ No newline at end of file |