// NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . #include "nel/misc/types_nl.h" #include #include #ifdef NL_OS_WINDOWS # include # include #endif #include #include #include "nel/misc/debug.h" #include "nel/misc/file.h" #include "nel/misc/path.h" #include "nel/misc/algo.h" #include "nel/misc/common.h" #include "nel/misc/big_file.h" #include "nel/misc/cmd_args.h" using namespace std; using namespace NLMISC; // --------------------------------------------------------------------------- class CWildCard { public: string Expression; bool Not; }; std::vector WildCards; // --------------------------------------------------------------------------- bool keepFile (const std::string &fileName) { uint i; bool ifPresent = false; bool ifTrue = false; string file = toLower(CFile::getFilename (fileName)); for (i=0; i pathContent; printf ("Treating directory: %s\n", srcDirectory.c_str()); CPath::getPathContent(srcDirectory, true, false, true, pathContent); // TODO: remove duplicate files // Sort filename sort (pathContent.begin(), pathContent.end(), i_comp); for (uint i=0; i filters; // If ? filters = args.getLongArg("if"); for (uint i = 0; i < filters.size(); ++i) { CWildCard card; card.Expression = toLower(filters[i]); card.Not = false; WildCards.push_back(card); } // If not ? filters = args.getLongArg("ifnot"); for (uint i = 0; i < filters.size(); ++i) { CWildCard card; card.Expression = toLower(filters[i]); card.Not = true; WildCards.push_back(card); } // Pack a directory std::string srcDirectory = args.getAdditionalArg("input").front(); if (!CFile::isDirectory(srcDirectory) || !CFile::isExists(srcDirectory)) { nlwarning("Error: %s doesn't exist or is not a directory!", srcDirectory.c_str()); } // Output directory or filename if (args.haveArg("o")) { gBNPHeader.BigFileName = args.getArg("o").front(); if (CFile::isDirectory(gBNPHeader.BigFileName)) { gBNPHeader.BigFileName = CPath::standardizePath(gBNPHeader.BigFileName) + CFile::getFilename(srcDirectory); } } else { gBNPHeader.BigFileName = CFile::getFilename(srcDirectory); } if (CFile::getExtension(gBNPHeader.BigFileName) != "bnp") gBNPHeader.BigFileName += ".bnp"; CFile::deleteFile(gBNPHeader.BigFileName); packSubRecurse(srcDirectory); return gBNPHeader.appendHeader() ? 0:-1; } if (args.haveArg("u")) { gBNPHeader.BigFileName = args.getAdditionalArg("input").front(); std::string dirName; // Output directory or filename if (args.haveArg("o")) { dirName = args.getArg("o").front(); } else { dirName = CFile::getFilenameWithoutExtension(gBNPHeader.BigFileName); } // Unpack a bnp file return gBNPHeader.unpack(dirName) ? 0:-1; } if (args.haveArg("l")) { gBNPHeader.BigFileName = args.getAdditionalArg("input").front(); // Read header of BNP file if (!gBNPHeader.readHeader()) return -1; for (uint i = 0; i < gBNPHeader.SFiles.size(); ++i) { printf("%s\n", gBNPHeader.SFiles[i].Name.c_str()); } return 0; } args.displayHelp(); return -1; }