Skip to content

Commit 0727ccc

Browse files
authored
v1.1
* show confirmation that the operation was completed * some code cleanup
1 parent c78e0c4 commit 0727ccc

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

FileToCArray.hpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ class ftca_form : public nana::form
2828
nana::place &plc{get_place()};
2929
const auto bg{nana::colors::white};
3030

31-
nana::API::track_window_size(handle(), {600, 185}, false);
32-
caption("File To C Array");
31+
caption("File To C Array v1.1");
3332
bgcolor(bg);
3433

3534
div("vert margin=15 < weight=20 <l_in weight=70><weight=15><l_inpath><weight=15><btn_in weight=20> >"
@@ -86,6 +85,22 @@ class ftca_form : public nana::form
8685
prog.scheme().gradient_fgcolor = nana::color{"#b7d3db"};
8786
prog.scheme().background = nana::color{"#e4e4e4"};
8887
prog.scheme().foreground = nana::color{"#64a3b5"};
88+
prog.typeface({typeface().name(), 11, nana::paint::font::font_style{800}});
89+
nana::drawing{prog}.draw([this] (nana::paint::graphics &graph)
90+
{
91+
auto caption{prog.caption()};
92+
if(!caption.empty())
93+
{
94+
auto tsize{graph.text_extent_size(caption)};
95+
auto gsize{graph.size()};
96+
nana::point pos{0,0};
97+
if(tsize.width < gsize.width)
98+
pos.x = gsize.width/2 - tsize.width/2;
99+
if(tsize.height < gsize.height)
100+
pos.y = gsize.height/2 - tsize.height/2;
101+
graph.string(pos, caption, nana::colors::white);
102+
}
103+
});
89104
plc["prog"] << prog;
90105

91106
collocate();
@@ -100,8 +115,8 @@ class ftca_form : public nana::form
100115
inpath = res.front();
101116
if(inpath == outpath)
102117
{
103-
outpath.replace_filename(std::wstring{L"arr_"} + outpath.filename().c_str());
104-
outpath.replace_extension(L"hpp");
118+
outpath.replace_filename("arr_" + outpath.filename().u8string());
119+
outpath.replace_extension("hpp");
105120
label_path_caption(l_outpath, outpath);
106121
}
107122
label_path_caption(l_inpath, inpath);
@@ -120,8 +135,8 @@ class ftca_form : public nana::form
120135
outpath = res.front();
121136
if(inpath == outpath)
122137
{
123-
outpath.replace_filename(std::wstring{L"arr_"} + outpath.filename().c_str());
124-
outpath.replace_extension(L"hpp");
138+
outpath.replace_filename("arr_" + outpath.filename().u8string());
139+
outpath.replace_extension("hpp");
125140
label_path_caption(l_outpath, outpath);
126141
}
127142
label_path_caption(l_outpath, outpath);
@@ -218,10 +233,11 @@ class ftca_form : public nana::form
218233
while(insize % width) width /= 2;
219234
auto buf{std::make_unique<char[]>(width)};
220235
const int prog_steps{568};
236+
prog.caption("");
221237
prog.amount(prog_steps);
222238
prog.value(0);
223239
uintmax_t prog_step{0}, step_treshold{0};
224-
if(insize >= 10000)
240+
if(insize >= 568)
225241
{
226242
prog_step = insize / prog_steps;
227243
step_treshold = prog_step;
@@ -232,7 +248,7 @@ class ftca_form : public nana::form
232248
std::ofstream outfile{outpath};
233249
if(!outfile.good()) throw(std::exception{"Failed to open the output file!"});
234250

235-
auto name{"arr_" + inpath.filename().generic_u8string()};
251+
auto name{"arr_" + inpath.filename().u8string()};
236252
for(auto &c : name) if(!isalnum(c)) c = '_';
237253

238254
outfile << "#include <cstdint>\n\n";
@@ -260,6 +276,7 @@ class ftca_form : public nana::form
260276
prog.inc();
261277
}
262278
if(abort) { working = false; return; }
279+
if(outfile.bad()) throw(std::exception{"Failed trying to write to the output file!"});
263280
}
264281

265282
if(infile.bad()) throw(std::exception{"Failed trying to read the input file!"});
@@ -268,6 +285,8 @@ class ftca_form : public nana::form
268285
if(line_chars_max) outfile << '\n';
269286
outfile << "};";
270287
btn_gen.caption(gen_text);
288+
prog.caption("Operation completed.");
289+
prog.value(prog_steps);
271290
working = false;
272291
}
273292

@@ -281,4 +300,4 @@ class ftca_form : public nana::form
281300
l.caption(L"..." + std::wstring{p.c_str()}.substr(offset));
282301
}
283302
}
284-
};
303+
};

0 commit comments

Comments
 (0)