mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 03:09:13 +00:00
Remove hsFiles in favor of plFilesystem stuff
This commit is contained in:
@ -83,7 +83,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#include "pfConsole/pfConsoleDirSrc.h"
|
||||
#include "plScene/plPageTreeMgr.h"
|
||||
#include "plScene/plVisMgr.h"
|
||||
#include "plFile/hsFiles.h"
|
||||
|
||||
#include "pfKI/pfKI.h"
|
||||
|
||||
@ -1635,19 +1634,17 @@ void plClient::IPatchGlobalAgeFiles( void )
|
||||
void plClient::InitDLLs()
|
||||
{
|
||||
hsStatusMessage("Init dlls client\n");
|
||||
char str[255];
|
||||
typedef void (*PInitGlobalsFunc) (hsResMgr *, plFactory *, plTimerCallbackManager *, plTimerShare*,
|
||||
plNetClientApp*);
|
||||
|
||||
hsFolderIterator modDllFolder("ModDLL\\");
|
||||
while (modDllFolder.NextFileSuffix(".dll"))
|
||||
std::vector<plFileName> dlls = plFileSystem::ListDir("ModDLL", "*.dll");
|
||||
for (auto iter = dlls.begin(); iter != dlls.end(); ++iter)
|
||||
{
|
||||
modDllFolder.GetPathAndName(str);
|
||||
HMODULE hMod = LoadLibrary(str);
|
||||
HMODULE hMod = LoadLibraryW(iter->AsString().ToWchar());
|
||||
if (hMod)
|
||||
{
|
||||
PInitGlobalsFunc initGlobals = (PInitGlobalsFunc)GetProcAddress(hMod, "InitGlobals");
|
||||
initGlobals(hsgResMgr::ResMgr(), plFactory::GetTheFactory(), plgTimerCallbackMgr::Mgr(),
|
||||
(*initGlobals)(hsgResMgr::ResMgr(), plFactory::GetTheFactory(), plgTimerCallbackMgr::Mgr(),
|
||||
hsTimer::GetTheTimer(), plNetClientApp::GetInstance());
|
||||
fLoadedDLLs.Append(hMod);
|
||||
}
|
||||
@ -2495,7 +2492,7 @@ void plClient::IOnAsyncInitComplete () {
|
||||
|
||||
// run fni in the Aux Init dir
|
||||
if (fpAuxInitDir)
|
||||
{
|
||||
{
|
||||
dirSrc.ParseDirectory(fpAuxInitDir, "net*.fni"); // connect to net first
|
||||
dirSrc.ParseDirectory(fpAuxInitDir, "*.fni");
|
||||
}
|
||||
|
@ -39,25 +39,25 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#include "plFile/hsFiles.h"
|
||||
#include "plFile/plEncryptedStream.h"
|
||||
#include "plProduct.h"
|
||||
|
||||
|
||||
void EncryptFiles(const char* dir, const char* ext, bool encrypt);
|
||||
void EncryptFiles(const plFileName& dir, const char* ext, bool encrypt);
|
||||
|
||||
void print_version() {
|
||||
printf("%s\n\n", plProduct::ProductString().c_str());
|
||||
puts(plProduct::ProductString().c_str());
|
||||
puts("");
|
||||
}
|
||||
|
||||
void print_help() {
|
||||
printf("plFileEncrypt - Encrypts and Decrypts Uru Files.\n\n");
|
||||
puts("plFileEncrypt - Encrypts and Decrypts Uru Files.\n");
|
||||
print_version();
|
||||
printf("Usage: plFileEncrypt \t[(encrypt|-e)|(decrypt|-d|)|(--help|-h|-?|/h)|(-v)]\n");
|
||||
printf("\tencrypt|-e\t - Encrypts All .age, .fni, .ini, .csv, and .sdl files in the current folder.\n");
|
||||
printf("\tdecrypt|-d\t - Decrypts All .age, .fni, .ini, .csv, and .sdl files in the current folder.\n");
|
||||
printf("\t--help|-h|-?|/h\t - Prints Help. This Screen.\n");
|
||||
printf("\t-v|--version\t - Prints build version information\n");
|
||||
puts("Usage: plFileEncrypt \t[(encrypt|-e)|(decrypt|-d|)|(--help|-h|-?|/h)|(-v)]");
|
||||
puts("\tencrypt|-e\t - Encrypts All .age, .fni, .ini, .csv, and .sdl files in the current folder.");
|
||||
puts("\tdecrypt|-d\t - Decrypts All .age, .fni, .ini, .csv, and .sdl files in the current folder.");
|
||||
puts("\t--help|-h|-?|/h\t - Prints Help. This Screen.");
|
||||
puts("\t-v|--version\t - Prints build version information");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -87,37 +87,34 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (ARGCMP("-v") || ARGCMP("--version"))
|
||||
{
|
||||
print_version();
|
||||
print_version();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#undef ARGCMP
|
||||
|
||||
EncryptFiles(dir, ".age", encrypt);
|
||||
EncryptFiles(dir, ".fni", encrypt);
|
||||
EncryptFiles(dir, ".ini", encrypt);
|
||||
EncryptFiles(dir, ".sdl", encrypt);
|
||||
EncryptFiles(dir, ".csv", encrypt);
|
||||
EncryptFiles(dir, "*.age", encrypt);
|
||||
EncryptFiles(dir, "*.fni", encrypt);
|
||||
EncryptFiles(dir, "*.ini", encrypt);
|
||||
EncryptFiles(dir, "*.sdl", encrypt);
|
||||
EncryptFiles(dir, "*.csv", encrypt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EncryptFiles(const char* dir, const char* ext, bool encrypt)
|
||||
void EncryptFiles(const plFileName& dir, const char* ext, bool encrypt)
|
||||
{
|
||||
char filePath[256];
|
||||
|
||||
hsFolderIterator folder(dir);
|
||||
while (folder.NextFileSuffix(ext))
|
||||
std::vector<plFileName> files = plFileSystem::ListDir(dir, ext);
|
||||
for (auto iter = files.begin(); iter != files.end(); ++iter)
|
||||
{
|
||||
folder.GetPathAndName(filePath);
|
||||
if (encrypt)
|
||||
{
|
||||
printf("encrypting: %s\n", folder.GetFileName());
|
||||
plEncryptedStream::FileEncrypt(filePath);
|
||||
printf("encrypting: %s\n", iter->GetFileName().c_str());
|
||||
plEncryptedStream::FileEncrypt(*iter);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("decrypting: %s\n", folder.GetFileName());
|
||||
plEncryptedStream::FileDecrypt(filePath);
|
||||
printf("decrypting: %s\n", iter->GetFileName().c_str());
|
||||
plEncryptedStream::FileDecrypt(*iter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
#include "plFile/hsFiles.h"
|
||||
#include "plFile/plSecureStream.h"
|
||||
#include "plProduct.h"
|
||||
|
||||
@ -48,26 +47,27 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#include <string>
|
||||
|
||||
void print_version() {
|
||||
printf("%s\n\n", plProduct::ProductString().c_str());
|
||||
puts(plProduct::ProductString().c_str());
|
||||
puts("");
|
||||
}
|
||||
|
||||
void print_help() {
|
||||
printf("plFileSecure - Secures Uru files and generates encryption.key files.\n\n");
|
||||
puts ("plFileSecure - Secures Uru files and generates encryption.key files.\n");
|
||||
print_version();
|
||||
printf("Usage:\n");
|
||||
printf("\tplFileSecure (<directory> <ext>)|[/generate /default]\n");
|
||||
printf("\n");
|
||||
printf("<directory> <ext> : The directory and extension of files to secure. Cannot\n");
|
||||
puts ("Usage:");
|
||||
puts ("\tplFileSecure (<directory> <ext>)|[/generate /default]");
|
||||
puts ("");
|
||||
puts ("<directory> <ext> : The directory and extension of files to secure. Cannot");
|
||||
printf(" be used with /generate. Uses the %s file in\n", plSecureStream::kKeyFilename);
|
||||
printf(" the current directory (or default key if no file exists)\n");
|
||||
puts (" the current directory (or default key if no file exists)");
|
||||
printf("/generate : Generates a random key and writes it to a %s\n", plSecureStream::kKeyFilename);
|
||||
printf(" file in the current directory. Cannot be used with\n");
|
||||
printf(" <directory> <ext>\n");
|
||||
puts (" file in the current directory. Cannot be used with");
|
||||
puts (" <directory> <ext>");
|
||||
printf("/default : If used with /generate, creates a %s file\n", plSecureStream::kKeyFilename);
|
||||
printf(" with the default key. If used with <directory> <ext>, it\n");
|
||||
printf(" secures with the default key instead of the\n");
|
||||
puts (" with the default key. If used with <directory> <ext>, it");
|
||||
puts (" secures with the default key instead of the");
|
||||
printf(" %s file's key\n", plSecureStream::kKeyFilename);
|
||||
printf("\n");
|
||||
puts ("");
|
||||
}
|
||||
|
||||
void GenerateKey(bool useDefault)
|
||||
@ -105,16 +105,13 @@ void GenerateKey(bool useDefault)
|
||||
out.Close();
|
||||
}
|
||||
|
||||
void SecureFiles(std::string dir, std::string ext, uint32_t* key)
|
||||
void SecureFiles(const plFileName& dir, const plString& ext, uint32_t* key)
|
||||
{
|
||||
char filePath[256];
|
||||
|
||||
hsFolderIterator folder(dir.c_str());
|
||||
while (folder.NextFileSuffix(ext.c_str()))
|
||||
std::vector<plFileName> files = plFileSystem::ListDir(dir, ext.c_str());
|
||||
for (auto iter = files.begin(); iter != files.end(); ++iter)
|
||||
{
|
||||
folder.GetPathAndName(filePath);
|
||||
printf("securing: %s\n", folder.GetFileName());
|
||||
plSecureStream::FileEncrypt(filePath, key);
|
||||
printf("securing: %s\n", iter->GetFileName());
|
||||
plSecureStream::FileEncrypt(*iter, key);
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,8 +119,8 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
bool generatingKey = false;
|
||||
bool useDefault = false;
|
||||
std::string directory;
|
||||
std::string ext;
|
||||
plFileName directory;
|
||||
plString ext;
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
@ -163,9 +160,9 @@ int main(int argc, char *argv[])
|
||||
else
|
||||
{
|
||||
// else it is a directory or extension
|
||||
if (directory == "")
|
||||
if (!directory.IsValid())
|
||||
directory = argv[i];
|
||||
else if (ext == "")
|
||||
else if (ext.IsEmpty())
|
||||
ext = argv[i];
|
||||
else
|
||||
{
|
||||
@ -175,7 +172,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (generatingKey && ((directory != "") || (ext != "")))
|
||||
if (generatingKey && ((directory.IsValid()) || (!ext.IsEmpty())))
|
||||
{
|
||||
print_help();
|
||||
return 0;
|
||||
@ -193,8 +190,11 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ext[0] != '.')
|
||||
ext = "." + ext; // tack on the dot if necessary
|
||||
// Make sure ext is a real pattern, or we won't find anything
|
||||
if (ext.CharAt(0) == '.')
|
||||
ext = "*" + ext;
|
||||
else if (ext.CharAt(0) != '*')
|
||||
ext = "*." + ext;
|
||||
|
||||
if (useDefault)
|
||||
SecureFiles(directory, ext, nil);
|
||||
|
@ -41,7 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
*==LICENSE==*/
|
||||
|
||||
#include "hsTimer.h"
|
||||
#include "plFile/hsFiles.h"
|
||||
#include "plResMgr/plResManager.h"
|
||||
#include "plResMgr/plResMgrSettings.h"
|
||||
|
||||
|
@ -45,10 +45,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#include "eval.h"
|
||||
#include "marshal.h"
|
||||
#include "cStringIO.h"
|
||||
#include "plFileSystem.h"
|
||||
|
||||
static PyObject* stdFile; // python object of the stdout and err file
|
||||
|
||||
void PythonInterface::initPython(std::string rootDir)
|
||||
void PythonInterface::initPython(const plFileName& rootDir)
|
||||
{
|
||||
// if haven't been initialized then do it
|
||||
if ( Py_IsInitialized() == 0 )
|
||||
@ -77,27 +78,27 @@ void PythonInterface::initPython(std::string rootDir)
|
||||
PyObject* sys_dict = PyModule_GetDict(sysmod);
|
||||
if (stdFile != nil)
|
||||
{
|
||||
PyDict_SetItemString(sys_dict,"stdout", stdFile);
|
||||
PyDict_SetItemString(sys_dict,"stderr", stdFile);
|
||||
PyDict_SetItemString(sys_dict, "stdout", stdFile);
|
||||
PyDict_SetItemString(sys_dict, "stderr", stdFile);
|
||||
}
|
||||
// NOTE: we will reset the path to not include paths
|
||||
// ...that Python may have found in the registery
|
||||
PyObject* path_list = PyList_New(0);
|
||||
printf("Setting up include dirs:\n");
|
||||
printf("%s\n",rootDir.c_str());
|
||||
PyObject* more_path = PyString_FromString(rootDir.c_str());
|
||||
printf("%s\n", rootDir.AsString().c_str());
|
||||
PyObject* more_path = PyString_FromString(rootDir.AsString().c_str());
|
||||
PyList_Append(path_list, more_path);
|
||||
// make sure that our plasma libraries are gotten before the system ones
|
||||
std::string temp = rootDir + "plasma";
|
||||
printf("%s\n",temp.c_str());
|
||||
PyObject* more_path3 = PyString_FromString(temp.c_str());
|
||||
plFileName temp = plFileName::Join(rootDir, "plasma");
|
||||
printf("%s\n", temp.AsString().c_str());
|
||||
PyObject* more_path3 = PyString_FromString(temp.AsString().c_str());
|
||||
PyList_Append(path_list, more_path3);
|
||||
temp = rootDir + "system";
|
||||
printf("%s\n\n",temp.c_str());
|
||||
temp = plFileName::Join(rootDir, "system");
|
||||
printf("%s\n\n", temp.AsString().c_str());
|
||||
PyObject* more_path2 = PyString_FromString("system");
|
||||
PyList_Append(path_list, more_path2);
|
||||
// set the path to be this one
|
||||
PyDict_SetItemString(sys_dict,"path",path_list);
|
||||
PyDict_SetItemString(sys_dict, "path", path_list);
|
||||
|
||||
|
||||
Py_DECREF(sysmod);
|
||||
@ -106,7 +107,7 @@ void PythonInterface::initPython(std::string rootDir)
|
||||
// initialized++;
|
||||
}
|
||||
|
||||
void PythonInterface::addPythonPath(std::string path)
|
||||
void PythonInterface::addPythonPath(const plFileName& path)
|
||||
{
|
||||
PyObject* sysmod = PyImport_ImportModule("sys");
|
||||
if (sysmod != NULL)
|
||||
@ -114,8 +115,8 @@ void PythonInterface::addPythonPath(std::string path)
|
||||
PyObject* sys_dict = PyModule_GetDict(sysmod);
|
||||
PyObject* path_list = PyDict_GetItemString(sys_dict, "path");
|
||||
|
||||
printf("Adding path %s\n", path.c_str());
|
||||
PyObject* more_path = PyString_FromString(path.c_str());
|
||||
printf("Adding path %s\n", path.AsString().c_str());
|
||||
PyObject* more_path = PyString_FromString(path.AsString().c_str());
|
||||
PyList_Append(path_list, more_path);
|
||||
|
||||
Py_DECREF(sysmod);
|
||||
@ -138,9 +139,9 @@ void PythonInterface::finiPython()
|
||||
//
|
||||
// PURPOSE : run a python string in a specific module name
|
||||
//
|
||||
PyObject* PythonInterface::CompileString(const char *command, const char* filename)
|
||||
PyObject* PythonInterface::CompileString(const char *command, const plFileName& filename)
|
||||
{
|
||||
PyObject* pycode = Py_CompileString(command, filename, Py_file_input);
|
||||
PyObject* pycode = Py_CompileString(command, filename.AsString().c_str(), Py_file_input);
|
||||
return pycode;
|
||||
}
|
||||
|
||||
|
@ -44,14 +44,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
|
||||
#include <string>
|
||||
|
||||
class plFileName;
|
||||
|
||||
namespace PythonInterface
|
||||
{
|
||||
void initPython(std::string rootDir);
|
||||
void initPython(const plFileName& rootDir);
|
||||
void finiPython();
|
||||
// So the Python packer can add extra paths
|
||||
void addPythonPath(std::string dir);
|
||||
void addPythonPath(const plFileName& dir);
|
||||
|
||||
PyObject* CompileString(const char *command, const char* filename);
|
||||
PyObject* CompileString(const char *command, const plFileName& filename);
|
||||
bool DumpObject(PyObject* pyobj, char** pickle, int32_t* size);
|
||||
int getOutputAndReset(char** line=nil);
|
||||
PyObject* CreateModule(const char* module);
|
||||
|
@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#include "PythonInterface.h"
|
||||
|
||||
#include "hsStream.h"
|
||||
#include "plFile/hsFiles.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@ -71,25 +70,24 @@ static const char* kPackFileName = "python.pak";
|
||||
#endif
|
||||
static char* glueFile = (char*)kGlueFile;
|
||||
|
||||
void WritePythonFile(std::string fileName, std::string path, hsStream *s)
|
||||
void WritePythonFile(const plFileName &fileName, const plFileName &path, hsStream *s)
|
||||
{
|
||||
hsUNIXStream pyStream, glueStream;
|
||||
std::string filePath;
|
||||
size_t filestart = fileName.find_last_of('.');
|
||||
if(filestart != std::string::npos)
|
||||
filePath = fileName.substr(filestart+1, std::string::npos);
|
||||
plFileName filePath;
|
||||
size_t filestart = fileName.AsString().FindLast('.');
|
||||
if (filestart >= 0)
|
||||
filePath = fileName.AsString().Substr(filestart+1);
|
||||
else
|
||||
filePath = fileName;
|
||||
filePath += ".py";
|
||||
filePath = path + filePath;
|
||||
filePath = plFileName::Join(path, filePath + ".py");
|
||||
|
||||
if (!pyStream.Open(filePath.c_str()) || !glueStream.Open(glueFile))
|
||||
if (!pyStream.Open(filePath) || !glueStream.Open(glueFile))
|
||||
{
|
||||
printf("Unable to open path %s, ",filePath.c_str());
|
||||
printf("Unable to open path %s, ", filePath.AsString().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
printf("==Packing %s, ",fileName.c_str());
|
||||
printf("==Packing %s, ", fileName.AsString().c_str());
|
||||
|
||||
pyStream.FastFwd();
|
||||
uint32_t pyFileSize = pyStream.GetPosition();
|
||||
@ -124,20 +122,20 @@ void WritePythonFile(std::string fileName, std::string path, hsStream *s)
|
||||
}
|
||||
|
||||
// import the module first, to make packages work correctly
|
||||
PyImport_ImportModule(fileName.c_str());
|
||||
PyObject* pythonCode = PythonInterface::CompileString(code, fileName.c_str());
|
||||
PyImport_ImportModule(fileName.AsString().c_str());
|
||||
PyObject* pythonCode = PythonInterface::CompileString(code, fileName);
|
||||
if (pythonCode)
|
||||
{
|
||||
// we need to find out if this is PythonFile module
|
||||
// create a module name... with the '.' as an X
|
||||
// and create a python file name that is without the ".py"
|
||||
PyObject* fModule = PythonInterface::CreateModule(fileName.c_str());
|
||||
PyObject* fModule = PythonInterface::CreateModule(fileName.AsString().c_str());
|
||||
// run the code
|
||||
if (PythonInterface::RunPYC(pythonCode, fModule) )
|
||||
{
|
||||
// set the name of the file (in the global dictionary of the module)
|
||||
PyObject* dict = PyModule_GetDict(fModule);
|
||||
PyObject* pfilename = PyString_FromString(fileName.c_str());
|
||||
PyObject* pfilename = PyString_FromString(fileName.AsString().c_str());
|
||||
PyDict_SetItemString(dict, "glue_name", pfilename);
|
||||
// next we need to:
|
||||
// - create instance of class
|
||||
@ -167,7 +165,7 @@ void WritePythonFile(std::string fileName, std::string path, hsStream *s)
|
||||
// else
|
||||
// skip the CRs
|
||||
}
|
||||
pythonCode = PythonInterface::CompileString(code, fileName.c_str());
|
||||
pythonCode = PythonInterface::CompileString(code, fileName);
|
||||
hsAssert(pythonCode,"Not sure why this didn't compile the second time???");
|
||||
printf("an import file ");
|
||||
}
|
||||
@ -227,23 +225,15 @@ void WritePythonFile(std::string fileName, std::string path, hsStream *s)
|
||||
glueStream.Close();
|
||||
}
|
||||
|
||||
void FindFiles(std::vector<std::string> &filenames, std::vector<std::string> &pathnames, const char* path)
|
||||
void FindFiles(std::vector<plFileName> &filenames, std::vector<plFileName> &pathnames, const plFileName& path)
|
||||
{
|
||||
// Get the names of all the python files
|
||||
hsFolderIterator folder;
|
||||
std::vector<plFileName> pys = plFileSystem::ListDir(path, "*.py");
|
||||
|
||||
// if there is a path... set it
|
||||
if ( path )
|
||||
folder.SetPath(path);
|
||||
|
||||
while (folder.NextFileSuffix(".py"))
|
||||
for (auto iter = pys.begin(); iter != pys.end(); ++iter)
|
||||
{
|
||||
const char *fileName = folder.GetFileName();
|
||||
filenames.push_back(fileName);
|
||||
if ( path )
|
||||
pathnames.push_back(path);
|
||||
else
|
||||
pathnames.push_back("");
|
||||
filenames.push_back(iter->GetFileName());
|
||||
pathnames.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,22 +250,13 @@ std::string ToLowerCase(std::string str)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void FindSubDirs(std::vector<std::string> &dirnames, const char *path)
|
||||
void FindSubDirs(std::vector<plFileName> &dirnames, const plFileName &path)
|
||||
{
|
||||
hsFolderIterator folder;
|
||||
if (path)
|
||||
folder.SetPath(path);
|
||||
|
||||
while (folder.NextFile())
|
||||
{
|
||||
if (folder.IsDirectory())
|
||||
{
|
||||
std::string dirName = folder.GetFileName();
|
||||
if ((dirName != ".")&&(dirName != "..")&&(ToLowerCase(dirName) != "system") && (ToLowerCase(dirName) != "plasma"))
|
||||
{
|
||||
dirnames.push_back(dirName);
|
||||
}
|
||||
}
|
||||
std::vector<plFileName> subdirs = plFileSystem::ListSubdirs(path);
|
||||
for (auto iter = subdirs.begin(); iter != subdirs.end(); ++iter) {
|
||||
plString name = iter->GetFileName();
|
||||
if (name.CompareI("system") != 0 && name.CompareI("plasma") != 0)
|
||||
dirnames.push_back(name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -343,66 +324,62 @@ std::string ConcatDirs(std::string fullPath, std::string partialPath)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void FindPackages(std::vector<std::string>& fileNames, std::vector<std::string>& pathNames, const char* path, std::string parent_package="")
|
||||
void FindPackages(std::vector<plFileName>& fileNames, std::vector<plFileName>& pathNames, const plFileName& path, const plString& parent_package="")
|
||||
{
|
||||
std::vector<std::string> packages;
|
||||
std::vector<plFileName> packages;
|
||||
FindSubDirs(packages, path);
|
||||
for (int i = 0; i < packages.size(); i++)
|
||||
{
|
||||
std::string packageName;
|
||||
if(!parent_package.empty())
|
||||
plString packageName;
|
||||
if (!parent_package.IsEmpty())
|
||||
packageName = parent_package + ".";
|
||||
packageName += packages[i];
|
||||
std::vector<std::string> packageFileNames;
|
||||
std::vector<std::string> packagePathNames;
|
||||
std::string packagePath = path;
|
||||
packagePath += "/" + packages[i];
|
||||
FindFiles(packageFileNames, packagePathNames, packagePath.c_str());
|
||||
packageName += packages[i].AsString();
|
||||
std::vector<plFileName> packageFileNames;
|
||||
std::vector<plFileName> packagePathNames;
|
||||
plFileName packagePath = plFileName::Join(path, packages[i]);
|
||||
FindFiles(packageFileNames, packagePathNames, packagePath);
|
||||
for (int j = 0; j < packageFileNames.size(); j++) {
|
||||
fileNames.push_back(packageName+"."+packageFileNames[j]);
|
||||
pathNames.push_back(packagePathNames[j]+"/");
|
||||
fileNames.push_back(packageName+"."+packageFileNames[j].AsString());
|
||||
pathNames.push_back(packagePathNames[j]);
|
||||
}
|
||||
FindPackages(fileNames, pathNames, packagePath.c_str(), packageName);
|
||||
FindPackages(fileNames, pathNames, packagePath, packageName);
|
||||
}
|
||||
}
|
||||
|
||||
void PackDirectory(std::string dir, std::string rootPath, std::string pakName, std::vector<std::string>& extraDirs, bool packSysAndPlasma = false)
|
||||
void PackDirectory(const plFileName& dir, const plFileName& rootPath, const plFileName& pakName, std::vector<plFileName>& extraDirs, bool packSysAndPlasma = false)
|
||||
{
|
||||
// make sure the dir ends in a slash
|
||||
dir = AdjustEndingSlash(dir,true);
|
||||
|
||||
printf("\nCreating %s using the contents of %s\n",pakName.c_str(),dir.c_str());
|
||||
printf("Changing working directory to %s\n",rootPath.c_str());
|
||||
if (chdir(rootPath.c_str()))
|
||||
printf("\nCreating %s using the contents of %s\n", pakName.AsString().c_str(), dir.AsString().c_str());
|
||||
printf("Changing working directory to %s\n", rootPath.AsString().c_str());
|
||||
if (!plFileSystem::SetCWD(rootPath))
|
||||
{
|
||||
printf("ERROR: Directory change to %s failed for some reason\n",rootPath.c_str());
|
||||
printf("ERROR: Directory change to %s failed for some reason\n", rootPath.AsString().c_str());
|
||||
printf("Unable to continue with the packing of this directory, aborting...\n");
|
||||
return;
|
||||
}
|
||||
else
|
||||
printf("Directory changed to %s\n",rootPath.c_str());
|
||||
printf("Directory changed to %s\n", rootPath.AsString().c_str());
|
||||
|
||||
std::vector<std::string> fileNames;
|
||||
std::vector<std::string> pathNames;
|
||||
std::vector<plFileName> fileNames;
|
||||
std::vector<plFileName> pathNames;
|
||||
|
||||
FindFiles(fileNames,pathNames,dir.c_str());
|
||||
FindPackages(fileNames,pathNames,dir.c_str());
|
||||
FindFiles(fileNames, pathNames, dir);
|
||||
FindPackages(fileNames, pathNames, dir);
|
||||
if (packSysAndPlasma)
|
||||
{
|
||||
printf("Adding the system and plasma directories to this pack file\n");
|
||||
std::string tempPath;
|
||||
tempPath = dir + "system/";
|
||||
FindFiles(fileNames,pathNames,tempPath.c_str());
|
||||
FindPackages(fileNames,pathNames,tempPath.c_str());
|
||||
tempPath = dir + "plasma/";
|
||||
FindFiles(fileNames,pathNames,tempPath.c_str());
|
||||
FindPackages(fileNames,pathNames,tempPath.c_str());
|
||||
plFileName tempPath;
|
||||
tempPath = plFileName::Join(dir, "system");
|
||||
FindFiles(fileNames, pathNames, tempPath);
|
||||
FindPackages(fileNames, pathNames, tempPath);
|
||||
tempPath = plFileName::Join(dir, "plasma");
|
||||
FindFiles(fileNames, pathNames, tempPath);
|
||||
FindPackages(fileNames, pathNames, tempPath);
|
||||
}
|
||||
|
||||
|
||||
// ok, we know how many files we're gonna pack, so make a fake index (we'll fill in later)
|
||||
hsUNIXStream s;
|
||||
if (!s.Open(pakName.c_str(), "wb"))
|
||||
if (!s.Open(pakName, "wb"))
|
||||
return;
|
||||
|
||||
s.WriteLE32(fileNames.size());
|
||||
@ -410,13 +387,13 @@ void PackDirectory(std::string dir, std::string rootPath, std::string pakName, s
|
||||
int i;
|
||||
for (i = 0; i < fileNames.size(); i++)
|
||||
{
|
||||
s.WriteSafeString(fileNames[i].c_str());
|
||||
s.WriteSafeString(fileNames[i].AsString());
|
||||
s.WriteLE32(0);
|
||||
}
|
||||
|
||||
PythonInterface::initPython(rootPath);
|
||||
for (i = 0; i < extraDirs.size(); i++)
|
||||
PythonInterface::addPythonPath(rootPath + extraDirs[i]);
|
||||
PythonInterface::addPythonPath(plFileName::Join(rootPath, extraDirs[i]));
|
||||
|
||||
// set to maximum optimization (includes removing __doc__ strings)
|
||||
Py_OptimizeFlag = 2;
|
||||
@ -427,7 +404,7 @@ void PackDirectory(std::string dir, std::string rootPath, std::string pakName, s
|
||||
for (i = 0; i < fileNames.size(); i++)
|
||||
{
|
||||
// strip '.py' from the file name
|
||||
std::string properFileName = fileNames[i].substr(0, fileNames[i].size()-3);
|
||||
plFileName properFileName = fileNames[i].StripFileExt();
|
||||
uint32_t initialPos = s.GetPosition();
|
||||
WritePythonFile(properFileName, pathNames[i], &s);
|
||||
uint32_t endPos = s.GetPosition();
|
||||
@ -438,7 +415,7 @@ void PackDirectory(std::string dir, std::string rootPath, std::string pakName, s
|
||||
s.SetPosition(sizeof(uint32_t));
|
||||
for (i = 0; i < fileNames.size(); i++)
|
||||
{
|
||||
s.WriteSafeString(fileNames[i].c_str());
|
||||
s.WriteSafeString(fileNames[i].AsString());
|
||||
s.WriteLE32(filePositions[i]);
|
||||
}
|
||||
|
||||
@ -459,9 +436,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
printf("The Python Pack Utility\n");
|
||||
|
||||
char buffer[MAXPATHLEN];
|
||||
getcwd(buffer, MAXPATHLEN);
|
||||
std::string baseWorkingDir = buffer;
|
||||
plFileName baseWorkingDir = plFileSystem::GetCWD();
|
||||
|
||||
// are they asking for usage?
|
||||
if (argc == 2)
|
||||
@ -482,26 +457,25 @@ int main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::vector<std::string> dirNames;
|
||||
std::string rootPath;
|
||||
std::vector<plFileName> dirNames;
|
||||
plFileName rootPath;
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
FindSubDirs(dirNames,nil);
|
||||
rootPath = AdjustEndingSlash(baseWorkingDir,true);
|
||||
FindSubDirs(dirNames, "");
|
||||
rootPath = baseWorkingDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string path = argv[1];
|
||||
FindSubDirs(dirNames,argv[1]);
|
||||
rootPath = ConcatDirs(baseWorkingDir,path);
|
||||
rootPath = AdjustEndingSlash(rootPath,true);
|
||||
plFileName path = argv[1];
|
||||
FindSubDirs(dirNames, argv[1]);
|
||||
rootPath = plFileName::Join(baseWorkingDir, path);
|
||||
}
|
||||
|
||||
PackDirectory(rootPath,rootPath,rootPath+kPackFileName,dirNames,true);
|
||||
|
||||
PackDirectory(rootPath, rootPath, plFileName::Join(rootPath, kPackFileName), dirNames, true);
|
||||
for (int i=0; i<dirNames.size(); i++)
|
||||
{
|
||||
PackDirectory(dirNames[i],rootPath,rootPath+dirNames[i]+".pak",dirNames);
|
||||
PackDirectory(dirNames[i], rootPath, plFileName::Join(rootPath, dirNames[i]+".pak"), dirNames);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -47,7 +47,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
|
||||
#include "Pch.h"
|
||||
#include "hsThread.h"
|
||||
#include "plFile/hsFiles.h"
|
||||
#include <algorithm>
|
||||
#pragma hdrstop
|
||||
|
||||
|
Reference in New Issue
Block a user