Skip to content

Add Icon Resource & Make Code Compile with GCC #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions FileToCArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ class ftca_form : public nana::form
{
working = true;
if(!std::filesystem::exists(inpath))
#ifdef _MSC_VER
throw(std::exception{"Input file does not exist!"});
#else
throw std::runtime_error("Input file does not exist!");
#endif
auto insize = std::filesystem::file_size(inpath);
unsigned width = sizeof(uint64_t);
while(insize % width) width /= 2;
Expand All @@ -244,9 +248,19 @@ class ftca_form : public nana::form
}

std::ifstream infile{inpath, std::ios::binary};
if(!infile.good()) throw(std::exception{"Failed to open the input file!"});
if(!infile.good())
#ifdef _MSC_VER
throw(std::exception{"Failed to open the input file!"});
#else
throw std::runtime_error("Failed to open the input file!");
#endif
std::ofstream outfile{outpath};
if(!outfile.good()) throw(std::exception{"Failed to open the output file!"});
if(!outfile.good())
#ifdef _MSC_VER
throw(std::exception{"Failed to open the output file!"});
#else
throw std::runtime_error("Failed to open the output file!");
#endif

auto name{"arr_" + inpath.filename().u8string()};
for(auto &c : name) if(!isalnum(c)) c = '_';
Expand Down Expand Up @@ -276,10 +290,20 @@ class ftca_form : public nana::form
prog.inc();
}
if(abort) { working = false; return; }
if(outfile.bad()) throw(std::exception{"Failed trying to write to the output file!"});
if(outfile.bad())
#ifdef _MSC_VER
throw(std::exception{"Failed trying to write to the output file!"});
#else
throw std::runtime_error("Failed trying to write to the output file!");
#endif
}

if(infile.bad()) throw(std::exception{"Failed trying to read the input file!"});
if(infile.bad())
#ifdef _MSC_VER
throw(std::exception{"Failed trying to read the input file!"});
#else
throw std::runtime_error("Failed trying to read the input file!");
#endif

outfile.seekp(static_cast<std::streamoff>(outfile.tellp())-1);
if(line_chars_max) outfile << '\n';
Expand Down
5 changes: 4 additions & 1 deletion FileToCArray_main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "FileToCArray.hpp"

int main()
int main(int argc, char** argv)
{
ftca_form fm;
#if defined(__WIN32) || defined(_MSC_VER)
nana::API::window_icon(fm.handle(), nana::paint::image(argv[0]));
#endif
fm.show();
nana::exec();
}
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,27 @@ Protip: if the output file that you choose is the same as the input file, it wil

## Windows binary
https://github.com/ErrorFlynn/FileToCArray/releases/download/v1.1/FileToCArray_11.7z

## Building

### GNU GCC

```
g++ --std=c++17 FileToCArray_main.cpp -lnana -lpng -ljpeg -o FileToCArray
```

#### Building on Windows with MinGW/GCC

If compiling on Windows you will also need to link to some Windows standard libraries:

```
g++ --std=c++17 FileToCArray_main.cpp -lnana -lpng -ljpeg -lgdi32 -lcomdlg32 -mwindows -o FileToCArray
```

To add an icon resource do the following:

```
windres icon_resource.rc -o icon_resource.o

g++ --std=c++17 FileToCArray_main.cpp icon_resource.o -lnana -lpng -ljpeg -lgdi32 -lcomdlg32 -mwindows -o FileToCArray
```
1 change: 1 addition & 0 deletions icon_resource.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ID_ICON1 ICON "images/icon.ico"
Binary file added images/icon.ico
Binary file not shown.
31 changes: 31 additions & 0 deletions images/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.