zipios  2.2.0
Zipios – a small C++ library that provides easy access to .zip files.
appendzip.cpp
Go to the documentation of this file.
1 /*
2  Zipios -- a small C++ library that provides easy access to .zip files.
3 
4  Copyright (C) 2000-2007 Thomas Sondergaard
5  Copyright (C) 2015-2019 Made to Order Software Corporation
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21 
31 #include <cstdlib>
32 #include <cstring>
33 #include <iostream>
34 #include <fstream>
35 #include <stdint.h>
36 
37 
38 // static variables
39 namespace
40 {
41 
42 char *g_progname;
43 
44 
45 void usage()
46 {
47  // see the ZipFile::openEmbeddedZipFile() function for details...
48  std::cout << "Usage: " << g_progname << " exe-file zipfile" << std::endl;
49  std::cout << "This tool appends a zipfile at the end of any other file (most often a .exe under MS-Windows)." << std::endl;
50  std::cout << "The openEmbeddedZipFile() function can then be used to read the file." << std::endl;
51  exit(1);
52 }
53 
54 } // no name namespace
55 
56 
57 int main(int argc, char *argv[])
58 {
59  g_progname = argv[0];
60  char *e(strrchr(g_progname, '/'));
61  if(e)
62  {
63  g_progname = e + 1;
64  }
65  e = strrchr(g_progname, '\\');
66  if(e)
67  {
68  g_progname = e + 1;
69  }
70 
71  if(argc != 3)
72  {
73  usage();
74  }
75 
76  std::ofstream exef(argv[1], std::ios::app | std::ios::binary);
77  if(!exef)
78  {
79  std::cerr << g_progname << ":error: Unable to open " << argv[1] << " for writing" << std::endl;
80  usage();
81  }
82 
83  std::ifstream zipf(argv[2], std::ios::in | std::ios::binary);
84  if(!zipf)
85  {
86  std::cerr << g_progname << ":error: Unable to open " << argv[2] << " for reading." << std::endl;
87  usage();
88  }
89 
90  // get eof pos (to become zip file starting position).
91  uint32_t const zip_start = exef.tellp();
92  std::cout << "zip start will be at " << zip_start << std::endl;
93 
94  // Append zip file to exe file
95  exef << zipf.rdbuf();
96 
97  // write zipfile start offset to file
98  exef << static_cast<unsigned char>(zip_start);
99  exef << static_cast<unsigned char>(zip_start >> 8);
100  exef << static_cast<unsigned char>(zip_start >> 16);
101  exef << static_cast<unsigned char>(zip_start >> 24);
102  //zipios::writeUint32(zip_start, exef); -- TODO: delete once verified
103 
104  return 0;
105 }
106 
107 
108 // Local Variables:
109 // mode: cpp
110 // indent-tabs-mode: nil
111 // c-basic-offset: 4
112 // tab-width: 4
113 // End:
114 
115 // vim: ts=4 sw=4 et
int main(int argc, char *argv[])
Definition: appendzip.cpp:57