Added compression tool for the server list.

This commit is contained in:
lotodore
2008-07-03 08:36:58 +00:00
parent a9fc2a8045
commit c4f57d7981
2 changed files with 173 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
/***************************************************************************
* Copyright (C) 2008 by Lothar May *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <boost/filesystem.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
using namespace boost::filesystem;
int
main(int argc, char *argv[])
{
if (argc != 2)
{
cout << "Usage: zlib_compress <text input file>" << endl;
return 1;
}
// Use input file name, and write to input file with additional ".z".
path inputFilePath(argv[1]);
path outputFilePath(inputFilePath);
outputFilePath = change_extension(outputFilePath, extension(outputFilePath) + ".z");
// Check whether file exists.
if (!exists(inputFilePath))
{
cerr << "Input file does not exist." << endl;
return 2;
}
try {
ifstream inFile(inputFilePath.directory_string().c_str(), ios_base::in);
ofstream outFile(outputFilePath.directory_string().c_str(), ios_base::out | ios_base::binary);
boost::iostreams::filtering_streambuf<boost::iostreams::output> out;
out.push(boost::iostreams::zlib_compressor());
out.push(outFile);
boost::iostreams::copy(inFile, out);
cout << "Compression of \"" << inputFilePath.directory_string() << "\" to \"" << outputFilePath.directory_string() << "\" was successful." << endl;
} catch (...)
{
cerr << "Compression failed." << endl;
}
return 0;
}
+107
View File
@@ -0,0 +1,107 @@
# QMake pro-file for the file compression tool
isEmpty( PREFIX ) {
PREFIX=/usr
}
TEMPLATE = app
CODECFORSRC = UTF-8
#CONFIG += thread console embed_manifest_exe exceptions rtti stl warn_on release
CONFIG += thread console embed_manifest_exe exceptions rtti stl warn_on debug
UI_DIR = uics
TARGET = bin/zlib_compress
MOC_DIR = mocs
OBJECTS_DIR = obj
DEFINES += PREFIX=\"$${PREFIX}\"
QT -= core gui
INCLUDEPATH += . \
src
DEPENDPATH += . \
src
SOURCES += \
src/zlib_compress.cpp
win32 {
INCLUDEPATH += ../boost/
LIBPATH += ../boost/stage/lib
win32-g++{
LIBS += -llibboost_filesystem-mgw34-mt-1_35
LIBS += -llibboost_system-mgw34-mt-1_35
LIBS += -llibboost_iostreams-mgw34-mt-1_35
LIBS += -llibboost_zlib-mgw34-mt-1_35
}
LIBS += -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lole32 -luuid -luser32 -lmsimg32 -lshell32 -lkernel32
}
unix {
# workaround for problems with boost_filesystem exceptions
QMAKE_LFLAGS += -no_dead_strip_inits_and_terms
}
unix : !mac {
##### My release static build options
#QMAKE_CXXFLAGS += -ffunction-sections -fdata-sections
#QMAKE_LFLAGS += -Wl,--gc-sections
LIB_DIRS = $${PREFIX}/lib $${PREFIX}/lib64
BOOST_FS = boost_filesystem boost_filesystem-mt
BOOST_IOSTREAMS = boost_iostreams boost_iostreams-mt
for(dir, LIB_DIRS) {
exists($$dir) {
for(lib, BOOST_FS) {
exists($${dir}/lib$${lib}.so*) {
message("Found $$lib")
BOOST_FS = -l$$lib
}
}
for(lib, BOOST_IOSTREAMS) {
exists($${dir}/lib$${lib}.so*) {
message("Found $$lib")
BOOST_IOSTREAMS = -l$$lib
}
}
}
}
BOOST_LIBS = $$BOOST_FS $$BOOST_IOSTREAMS
!count(BOOST_LIBS, 2) {
error("could not locate required library: \
libboost (version >= 1.34.1) --> http://www.boost.org/")
}
#### INSTALL ####
binary.path += $${PREFIX}/bin/
binary.files += zlib_compress
INSTALLS += binary
}
mac{
# make it universal
CONFIG += x86
CONFIG += ppc
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.3
# for universal-compilation on PPC-Mac uncomment the following line
# on Intel-Mac you have to comment this line out or build will fail.
# QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk/
# standard path for darwinports
# make sure you have a universal version of boost
LIBS += /usr/local/lib/libboost_filesystem-mt-1_35.a
LIBS += /usr/local/lib/libboost_system-mt-1_35.a
LIBS += /usr/local/lib/libboost_iostreams-mt-1_35.a
# libraries installed on every mac
LIBPATH += /Developer/SDKs/MacOSX10.4u.sdk/usr/lib
INCLUDEPATH += /Developer/SDKs/MacOSX10.4u.sdk/usr/include/
}