45
|
1 // Filename : utils.cpp
|
48
|
2 // Last Change: 2020-04-22 09:21:01.
|
45
|
3 //
|
|
4 #include <wx/wx.h>
|
47
|
5 #include <wx/dir.h>
|
|
6 #include <wx/wfstream.h>
|
|
7 #include <wx/zstream.h>
|
|
8 #include <wx/tarstrm.h>
|
45
|
9 #include "utils.h"
|
|
10
|
|
11 wxRect Geo2Rect(wxString geo)
|
|
12 {
|
|
13 long w, h, x, y;
|
|
14 wxString sw = geo.BeforeFirst('x');
|
|
15 wxString sh = geo.AfterFirst('x').BeforeFirst('+');
|
|
16 wxString sx = geo.AfterFirst('+').BeforeFirst('+');
|
|
17 wxString sy = geo.AfterLast('+');
|
|
18
|
|
19 sw.ToLong(&w, 10);
|
|
20 sh.ToLong(&h, 10);
|
|
21 sx.ToLong(&x, 10);
|
|
22 sy.ToLong(&y, 10);
|
|
23
|
|
24 return wxRect((int)x, (int)y, (int)w, (int)h);
|
|
25 }
|
|
26
|
|
27 wxRect ZeroRect()
|
|
28 {
|
|
29 wxRect rect(wxPoint(0, 0), wxPoint(0, 0));
|
|
30 return rect;
|
|
31 }
|
|
32
|
47
|
33 bool TarDir(wxString dir, wxString tarfile)
|
|
34 {
|
|
35 if (!wxDirExists(dir)) {
|
|
36 wxMessageBox(wxT("bad directoy"));
|
|
37 return false;
|
|
38 }
|
|
39
|
|
40 wxDir d(dir);
|
|
41 if (!d.IsOpened()) return false;
|
|
42
|
|
43 wxFFileOutputStream out(tarfile);
|
|
44 wxTarOutputStream tar(out);
|
|
45
|
|
46 wxString filename;
|
|
47 bool cont = d.GetFirst(&filename, wxEmptyString, wxDIR_FILES);
|
|
48 while (cont) {
|
|
49 wxFFileInputStream in(dir + wxFILE_SEP_PATH + filename);
|
48
|
50 tar.PutNextEntry(filename);
|
47
|
51 tar.Write(in);
|
|
52 cont = d.GetNext(&filename);
|
|
53 }
|
|
54 tar.Close();
|
|
55 return true;
|
|
56 }
|
|
57
|
|
58 bool Gzip(wxString infile, wxString gzfile)
|
|
59 {
|
|
60 wxFileInputStream istream(infile);
|
|
61 wxFileOutputStream ostream(gzfile);
|
|
62 wxZlibOutputStream zstream(ostream, -1, wxZLIB_GZIP);
|
|
63
|
|
64 zstream.Write(istream);
|
|
65 zstream.Close();
|
|
66 return true;
|
|
67 }
|
|
68
|