zipios++  2.0.2
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 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 
31 #include <cstdlib>
32 #include <cstring>
33 #include <iostream>
34 #include <fstream>
35 
36 
37 // static variables
38 namespace
39 {
40 
41 char *g_progname;
42 
43 
44 void usage()
45 {
46  // see the ZipFile::openEmbeddedZipFile() function for details...
47  std::cout << "Usage: " << g_progname << " exe-file zipfile" << std::endl;
48  std::cout << "This tool appends a zipfile at the end of any other file (most often a .exe under MS-Windows)." << std::endl;
49  std::cout << "The openEmbeddedZipFile() function can then be used to read the file." << std::endl;
50  exit(1);
51 }
52 
53 } // no name namespace
54 
55 
56 int main(int argc, char *argv[])
57 {
58  g_progname = argv[0];
59  char *e(strrchr(g_progname, '/'));
60  if(e)
61  {
62  g_progname = e + 1;
63  }
64  e = strrchr(g_progname, '\\');
65  if(e)
66  {
67  g_progname = e + 1;
68  }
69 
70  if(argc != 3)
71  {
72  usage();
73  }
74 
75  std::ofstream exef(argv[1], std::ios::app | std::ios::binary);
76  if(!exef)
77  {
78  std::cerr << g_progname << ":error: Unable to open " << argv[1] << " for writing" << std::endl;
79  usage();
80  }
81 
82  std::ifstream zipf(argv[2], std::ios::in | std::ios::binary);
83  if(!zipf)
84  {
85  std::cerr << g_progname << ":error: Unable to open " << argv[2] << " for reading." << std::endl;
86  usage();
87  }
88 
89  // get eof pos (to become zip file starting position).
90  uint32_t const zip_start = exef.tellp();
91  std::cout << "zip start will be at " << zip_start << std::endl;
92 
93  // Append zip file to exe file
94  exef << zipf.rdbuf();
95 
96  // write zipfile start offset to file
97  exef << static_cast<unsigned char>(zip_start);
98  exef << static_cast<unsigned char>(zip_start >> 8);
99  exef << static_cast<unsigned char>(zip_start >> 16);
100  exef << static_cast<unsigned char>(zip_start >> 24);
101  //zipios::writeUint32(zip_start, exef); -- TODO: delete once verified
102 
103  return 0;
104 }
105 
106 
107 // Local Variables:
108 // mode: cpp
109 // indent-tabs-mode: nil
110 // c-basic-offset: 4
111 // tab-width: 4
112 // End:
113 
114 // vim: ts=4 sw=4 et
int main(int argc, char *argv[])
Definition: appendzip.cpp:56