mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-25 10:41:34 +00:00
anonymous namespace
This commit is contained in:
parent
454b64974d
commit
641b7b0336
1 changed files with 281 additions and 278 deletions
|
@ -5,17 +5,18 @@
|
||||||
|
|
||||||
namespace bfs = boost::filesystem;
|
namespace bfs = boost::filesystem;
|
||||||
|
|
||||||
|
namespace
|
||||||
typedef enum
|
|
||||||
{
|
{
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
FORMAT_NEW,
|
FORMAT_NEW,
|
||||||
FORMAT_OLD,
|
FORMAT_OLD,
|
||||||
FORMAT_RAW
|
FORMAT_RAW
|
||||||
} FORMAT;
|
} FORMAT;
|
||||||
|
|
||||||
|
|
||||||
static bool make_sure_directory_exists(bfs::path directory)
|
static bool make_sure_directory_exists(bfs::path directory)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!bfs::exists(directory))
|
if(!bfs::exists(directory))
|
||||||
{
|
{
|
||||||
|
@ -23,10 +24,10 @@ static bool make_sure_directory_exists(bfs::path directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
return bfs::exists(directory);
|
return bfs::exists(directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fill_path(bfs::path& path, const std::string& name)
|
void fill_path(bfs::path& path, const std::string& name)
|
||||||
{
|
{
|
||||||
size_t start = 0;
|
size_t start = 0;
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -42,85 +43,20 @@ void fill_path(bfs::path& path, const std::string& name)
|
||||||
}
|
}
|
||||||
|
|
||||||
path /= name.substr(start, i-start);
|
path /= name.substr(start, i-start);
|
||||||
}
|
|
||||||
|
|
||||||
bool UnshieldThread::extract_file(Unshield* unshield, bfs::path output_dir, const char* prefix, int index)
|
|
||||||
{
|
|
||||||
bool success;
|
|
||||||
bfs::path dirname;
|
|
||||||
bfs::path filename;
|
|
||||||
int directory = unshield_file_directory(unshield, index);
|
|
||||||
|
|
||||||
dirname = output_dir;
|
|
||||||
|
|
||||||
if (prefix && prefix[0])
|
|
||||||
dirname /= prefix;
|
|
||||||
|
|
||||||
if (directory >= 0)
|
|
||||||
{
|
|
||||||
const char* tmp = unshield_directory_name(unshield, directory);
|
|
||||||
if (tmp && tmp[0])
|
|
||||||
fill_path(dirname, tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
make_sure_directory_exists(dirname);
|
std::string get_setting(const std::string& category, const std::string& setting, const std::string& inx)
|
||||||
|
|
||||||
filename = dirname;
|
|
||||||
filename /= unshield_file_name(unshield, index);
|
|
||||||
|
|
||||||
emit signalGUI(QString("Extracting: ") + QString(filename.c_str()));
|
|
||||||
|
|
||||||
FORMAT format = FORMAT_NEW;
|
|
||||||
switch (format)
|
|
||||||
{
|
{
|
||||||
case FORMAT_NEW:
|
|
||||||
success = unshield_file_save(unshield, index, filename.c_str());
|
|
||||||
break;
|
|
||||||
case FORMAT_OLD:
|
|
||||||
success = unshield_file_save_old(unshield, index, filename.c_str());
|
|
||||||
break;
|
|
||||||
case FORMAT_RAW:
|
|
||||||
success = unshield_file_save_raw(unshield, index, filename.c_str());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!success)
|
|
||||||
bfs::remove(filename);
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UnshieldThread::extract_cab(const bfs::path& cab, const bfs::path& output_dir, bool extract_ini)
|
|
||||||
{
|
|
||||||
Unshield * unshield;
|
|
||||||
unshield = unshield_open_force_version(cab.c_str(), -1);
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < unshield_file_group_count(unshield); i++)
|
|
||||||
{
|
|
||||||
UnshieldFileGroup* file_group = unshield_file_group_get(unshield, i);
|
|
||||||
|
|
||||||
for (size_t j = file_group->first_file; j <= file_group->last_file; j++)
|
|
||||||
{
|
|
||||||
if (unshield_file_is_valid(unshield, j))
|
|
||||||
extract_file(unshield, output_dir, file_group->name, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unshield_close(unshield);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string get_setting(const std::string& category, const std::string& setting, const std::string& inx)
|
|
||||||
{
|
|
||||||
size_t start = inx.find(category);
|
size_t start = inx.find(category);
|
||||||
start = inx.find(setting, start) + setting.length() + 3;
|
start = inx.find(setting, start) + setting.length() + 3;
|
||||||
|
|
||||||
size_t end = inx.find("!", start);
|
size_t end = inx.find("!", start);
|
||||||
|
|
||||||
return inx.substr(start, end-start);
|
return inx.substr(start, end-start);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string read_to_string(const bfs::path& path)
|
std::string read_to_string(const bfs::path& path)
|
||||||
{
|
{
|
||||||
std::ifstream strstream(path.c_str(), std::ios::in | std::ios::binary);
|
std::ifstream strstream(path.c_str(), std::ios::in | std::ios::binary);
|
||||||
std::string str;
|
std::string str;
|
||||||
|
|
||||||
|
@ -131,10 +67,10 @@ std::string read_to_string(const bfs::path& path)
|
||||||
strstream.close();
|
strstream.close();
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_setting(const std::string& category, const std::string& setting, const std::string& val, std::string& ini)
|
void add_setting(const std::string& category, const std::string& setting, const std::string& val, std::string& ini)
|
||||||
{
|
{
|
||||||
size_t loc;
|
size_t loc;
|
||||||
loc = ini.find("[" + category + "]");
|
loc = ini.find("[" + category + "]");
|
||||||
|
|
||||||
|
@ -147,10 +83,10 @@ void add_setting(const std::string& category, const std::string& setting, const
|
||||||
|
|
||||||
loc += category.length() +2 +2;
|
loc += category.length() +2 +2;
|
||||||
ini.insert(loc, setting + "=" + val + "\r\n");
|
ini.insert(loc, setting + "=" + val + "\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void bloodmoon_fix_ini(std::string& ini, const bfs::path inxPath)
|
void bloodmoon_fix_ini(std::string& ini, const bfs::path inxPath)
|
||||||
{
|
{
|
||||||
std::string inx = read_to_string(inxPath);
|
std::string inx = read_to_string(inxPath);
|
||||||
|
|
||||||
// Remove this one setting (the only one actually changed by bloodmoon, as opposed to just adding new ones)
|
// Remove this one setting (the only one actually changed by bloodmoon, as opposed to just adding new ones)
|
||||||
|
@ -250,11 +186,11 @@ void bloodmoon_fix_ini(std::string& ini, const bfs::path inxPath)
|
||||||
setting = "Ambient Loop Sound ID"; add_setting(category, setting, get_setting(category, setting, inx), ini);
|
setting = "Ambient Loop Sound ID"; add_setting(category, setting, get_setting(category, setting, inx), ini);
|
||||||
setting = "Storm Threshold"; add_setting(category, setting, get_setting(category, setting, inx), ini);
|
setting = "Storm Threshold"; add_setting(category, setting, get_setting(category, setting, inx), ini);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void fix_ini(const bfs::path& output_dir, bfs::path cdPath, bool tribunal, bool bloodmoon)
|
void fix_ini(const bfs::path& output_dir, bfs::path cdPath, bool tribunal, bool bloodmoon)
|
||||||
{
|
{
|
||||||
bfs::path ini_path = output_dir;
|
bfs::path ini_path = output_dir;
|
||||||
ini_path /= "Morrowind.ini";
|
ini_path /= "Morrowind.ini";
|
||||||
|
|
||||||
|
@ -275,6 +211,66 @@ void fix_ini(const bfs::path& output_dir, bfs::path cdPath, bool tribunal, bool
|
||||||
std::ofstream inistream(ini_path.c_str());
|
std::ofstream inistream(ini_path.c_str());
|
||||||
inistream << ini;
|
inistream << ini;
|
||||||
inistream.close();
|
inistream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void installToPath(const bfs::path& from, const bfs::path& to, bool copy = false)
|
||||||
|
{
|
||||||
|
make_sure_directory_exists(to);
|
||||||
|
|
||||||
|
for ( bfs::directory_iterator end, dir(from); dir != end; ++dir )
|
||||||
|
{
|
||||||
|
if(bfs::is_directory(dir->path()))
|
||||||
|
installToPath(dir->path(), to / dir->path().filename());
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!copy)
|
||||||
|
bfs::rename(dir->path(), to / dir->path().filename());
|
||||||
|
else
|
||||||
|
bfs::copy_file(dir->path(), to / dir->path().filename());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bfs::path findFile(const bfs::path& in, std::string filename, bool recursive = true)
|
||||||
|
{
|
||||||
|
if(recursive)
|
||||||
|
{
|
||||||
|
for ( bfs::recursive_directory_iterator end, dir(in); dir != end; ++dir )
|
||||||
|
{
|
||||||
|
if(Misc::StringUtils::lowerCase(dir->path().filename().string()) == filename)
|
||||||
|
return dir->path();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for ( bfs::recursive_directory_iterator end, dir(in); dir != end; ++dir )
|
||||||
|
{
|
||||||
|
if(Misc::StringUtils::lowerCase(dir->path().filename().string()) == filename)
|
||||||
|
return dir->path();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool contains(const bfs::path& in, std::string filename)
|
||||||
|
{
|
||||||
|
for(bfs::directory_iterator end, dir(in); dir != end; ++dir)
|
||||||
|
{
|
||||||
|
if(Misc::StringUtils::lowerCase(dir->path().filename().string()) == filename)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t getTime(const char* time)
|
||||||
|
{
|
||||||
|
struct tm tms;
|
||||||
|
memset(&tms, 0, sizeof(struct tm));
|
||||||
|
strptime(time, "%d %B %Y", &tms);
|
||||||
|
return mktime(&tms);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UnshieldThread::SetMorrowindPath(const std::string& path)
|
bool UnshieldThread::SetMorrowindPath(const std::string& path)
|
||||||
|
@ -300,56 +296,71 @@ void UnshieldThread::SetOutputPath(const std::string& path)
|
||||||
mOutputPath = path;
|
mOutputPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void installToPath(const bfs::path& from, const bfs::path& to, bool copy = false)
|
bool UnshieldThread::extract_file(Unshield* unshield, bfs::path output_dir, const char* prefix, int index)
|
||||||
{
|
{
|
||||||
make_sure_directory_exists(to);
|
bool success;
|
||||||
|
bfs::path dirname;
|
||||||
|
bfs::path filename;
|
||||||
|
int directory = unshield_file_directory(unshield, index);
|
||||||
|
|
||||||
for ( bfs::directory_iterator end, dir(from); dir != end; ++dir )
|
dirname = output_dir;
|
||||||
|
|
||||||
|
if (prefix && prefix[0])
|
||||||
|
dirname /= prefix;
|
||||||
|
|
||||||
|
if (directory >= 0)
|
||||||
{
|
{
|
||||||
if(bfs::is_directory(dir->path()))
|
const char* tmp = unshield_directory_name(unshield, directory);
|
||||||
installToPath(dir->path(), to / dir->path().filename());
|
if (tmp && tmp[0])
|
||||||
else
|
fill_path(dirname, tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
make_sure_directory_exists(dirname);
|
||||||
|
|
||||||
|
filename = dirname;
|
||||||
|
filename /= unshield_file_name(unshield, index);
|
||||||
|
|
||||||
|
emit signalGUI(QString("Extracting: ") + QString(filename.c_str()));
|
||||||
|
|
||||||
|
FORMAT format = FORMAT_NEW;
|
||||||
|
switch (format)
|
||||||
{
|
{
|
||||||
if(!copy)
|
case FORMAT_NEW:
|
||||||
bfs::rename(dir->path(), to / dir->path().filename());
|
success = unshield_file_save(unshield, index, filename.c_str());
|
||||||
else
|
break;
|
||||||
bfs::copy_file(dir->path(), to / dir->path().filename());
|
case FORMAT_OLD:
|
||||||
}
|
success = unshield_file_save_old(unshield, index, filename.c_str());
|
||||||
|
break;
|
||||||
|
case FORMAT_RAW:
|
||||||
|
success = unshield_file_save_raw(unshield, index, filename.c_str());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
bfs::remove(filename);
|
||||||
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bfs::path findFile(const bfs::path& in, std::string filename, bool recursive = true)
|
void UnshieldThread::extract_cab(const bfs::path& cab, const bfs::path& output_dir, bool extract_ini)
|
||||||
{
|
{
|
||||||
if(recursive)
|
Unshield * unshield;
|
||||||
{
|
unshield = unshield_open_force_version(cab.c_str(), -1);
|
||||||
for ( bfs::recursive_directory_iterator end, dir(in); dir != end; ++dir )
|
|
||||||
{
|
|
||||||
if(Misc::StringUtils::lowerCase(dir->path().filename().string()) == filename)
|
|
||||||
return dir->path();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for ( bfs::recursive_directory_iterator end, dir(in); dir != end; ++dir )
|
|
||||||
{
|
|
||||||
if(Misc::StringUtils::lowerCase(dir->path().filename().string()) == filename)
|
|
||||||
return dir->path();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
int i;
|
||||||
|
for (i = 0; i < unshield_file_group_count(unshield); i++)
|
||||||
|
{
|
||||||
|
UnshieldFileGroup* file_group = unshield_file_group_get(unshield, i);
|
||||||
|
|
||||||
|
for (size_t j = file_group->first_file; j <= file_group->last_file; j++)
|
||||||
|
{
|
||||||
|
if (unshield_file_is_valid(unshield, j))
|
||||||
|
extract_file(unshield, output_dir, file_group->name, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unshield_close(unshield);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool contains(const bfs::path& in, std::string filename)
|
|
||||||
{
|
|
||||||
for(bfs::directory_iterator end, dir(in); dir != end; ++dir)
|
|
||||||
{
|
|
||||||
if(Misc::StringUtils::lowerCase(dir->path().filename().string()) == filename)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UnshieldThread::extract()
|
bool UnshieldThread::extract()
|
||||||
{
|
{
|
||||||
|
@ -429,14 +440,6 @@ bool UnshieldThread::extract()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t getTime(const char* time)
|
|
||||||
{
|
|
||||||
struct tm tms;
|
|
||||||
memset(&tms, 0, sizeof(struct tm));
|
|
||||||
strptime(time, "%d %B %Y", &tms);
|
|
||||||
return mktime(&tms);
|
|
||||||
}
|
|
||||||
|
|
||||||
void UnshieldThread::Done()
|
void UnshieldThread::Done()
|
||||||
{
|
{
|
||||||
// Get rid of unnecessary files
|
// Get rid of unnecessary files
|
||||||
|
|
Loading…
Reference in a new issue