anonymous namespace

actorid
Tom Mason 12 years ago
parent 454b64974d
commit 641b7b0336

@ -5,276 +5,272 @@
namespace bfs = boost::filesystem; namespace bfs = boost::filesystem;
namespace
{
typedef enum
{
FORMAT_NEW,
FORMAT_OLD,
FORMAT_RAW
} FORMAT;
typedef enum
{
FORMAT_NEW,
FORMAT_OLD,
FORMAT_RAW
} FORMAT;
static bool make_sure_directory_exists(bfs::path directory)
{
static bool make_sure_directory_exists(bfs::path directory) if(!bfs::exists(directory))
{ {
bfs::create_directories(directory);
}
if(!bfs::exists(directory)) return bfs::exists(directory);
{
bfs::create_directories(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 i;
for(i = 0; i < name.length(); i++)
{ {
switch(name[i]) size_t start = 0;
size_t i;
for(i = 0; i < name.length(); i++)
{ {
case '\\': switch(name[i])
path /= name.substr(start, i-start); {
start = i+1; case '\\':
break; path /= name.substr(start, i-start);
start = i+1;
break;
}
} }
}
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) std::string get_setting(const std::string& category, const std::string& setting, const std::string& inx)
{ {
const char* tmp = unshield_directory_name(unshield, directory); size_t start = inx.find(category);
if (tmp && tmp[0]) start = inx.find(setting, start) + setting.length() + 3;
fill_path(dirname, tmp);
}
make_sure_directory_exists(dirname); size_t end = inx.find("!", start);
filename = dirname; return inx.substr(start, end-start);
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) std::string read_to_string(const bfs::path& path)
bfs::remove(filename); {
std::ifstream strstream(path.c_str(), std::ios::in | std::ios::binary);
std::string str;
return success; strstream.seekg(0, std::ios::end);
} str.resize(strstream.tellg());
strstream.seekg(0, std::ios::beg);
strstream.read(&str[0], str.size());
strstream.close();
void UnshieldThread::extract_cab(const bfs::path& cab, const bfs::path& output_dir, bool extract_ini) return str;
{ }
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++) void add_setting(const std::string& category, const std::string& setting, const std::string& val, std::string& ini)
{
size_t loc;
loc = ini.find("[" + category + "]");
// If category is not found, create it
if(loc == std::string::npos)
{ {
if (unshield_file_is_valid(unshield, j)) loc = ini.size() + 2;
extract_file(unshield, output_dir, file_group->name, j); ini += ("\r\n[" + category + "]\r\n");
} }
loc += category.length() +2 +2;
ini.insert(loc, setting + "=" + val + "\r\n");
} }
unshield_close(unshield);
}
std::string get_setting(const std::string& category, const std::string& setting, const std::string& inx) void bloodmoon_fix_ini(std::string& ini, const bfs::path inxPath)
{ {
size_t start = inx.find(category); std::string inx = read_to_string(inxPath);
start = inx.find(setting, start) + setting.length() + 3;
size_t end = inx.find("!", start); // Remove this one setting (the only one actually changed by bloodmoon, as opposed to just adding new ones)
size_t start = ini.find("[Weather Blight]");
start = ini.find("Ambient Loop Sound ID", start);
size_t end = ini.find("\r\n", start) +2;
ini.erase(start, end-start);
return inx.substr(start, end-start); std::string category;
} std::string setting;
std::string read_to_string(const bfs::path& path) category = "General";
{ {
std::ifstream strstream(path.c_str(), std::ios::in | std::ios::binary); setting = "Werewolf FOV"; add_setting(category, setting, get_setting(category, setting, inx), ini);
std::string str; }
category = "Moons";
strstream.seekg(0, std::ios::end); {
str.resize(strstream.tellg()); setting = "Script Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
strstream.seekg(0, std::ios::beg); }
strstream.read(&str[0], str.size()); category = "Weather";
strstream.close(); {
setting = "Snow Ripples"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Ripple Radius"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Ripples Per Flake"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Ripple Scale"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Ripple Speed"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Gravity Scale"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow High Kill"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Low Kill"; add_setting(category, setting, get_setting(category, setting, inx), ini);
}
category = "Weather Blight";
{
setting = "Ambient Loop Sound ID"; add_setting(category, setting, get_setting(category, setting, inx), ini);
}
category = "Weather Snow";
{
setting = "Sky Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sky Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sky Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sky Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Disc Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Transition Delta"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Land Fog Day Depth"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Land Fog Night Depth"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Clouds Maximum Percent"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Wind Speed"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Cloud Speed"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Glare View"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Cloud Texture"; 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 = "Snow Threshold"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Diameter"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Height Min"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Height Max"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Entrance Speed"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Max Snowflakes"; add_setting(category, setting, get_setting(category, setting, inx), ini);
}
category = "Weather Blizzard";
{
setting = "Sky Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sky Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sky Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sky Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Disc Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Transition Delta"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Land Fog Day Depth"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Land Fog Night Depth"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Clouds Maximum Percent"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Wind Speed"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Cloud Speed"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Glare View"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Cloud Texture"; 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);
}
}
return str;
}
void add_setting(const std::string& category, const std::string& setting, const std::string& val, std::string& ini) void fix_ini(const bfs::path& output_dir, bfs::path cdPath, bool tribunal, bool bloodmoon)
{
size_t loc;
loc = ini.find("[" + category + "]");
// If category is not found, create it
if(loc == std::string::npos)
{ {
loc = ini.size() + 2; bfs::path ini_path = output_dir;
ini += ("\r\n[" + category + "]\r\n"); ini_path /= "Morrowind.ini";
}
loc += category.length() +2 +2;
ini.insert(loc, setting + "=" + val + "\r\n");
}
void bloodmoon_fix_ini(std::string& ini, const bfs::path 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) std::string ini = read_to_string(ini_path.string());
size_t start = ini.find("[Weather Blight]");
start = ini.find("Ambient Loop Sound ID", start);
size_t end = ini.find("\r\n", start) +2;
ini.erase(start, end-start);
std::string category; if(tribunal)
std::string setting; {
add_setting("Game Files", "GameFile1", "Tribunal.esm", ini);
add_setting("Archives", "Archive 0", "Tribunal.bsa", ini);
}
if(bloodmoon)
{
bloodmoon_fix_ini(ini, cdPath / "setup.inx");
add_setting("Game Files", "GameFile2", "Bloodmoon.esm", ini);
add_setting("Archives", "Archive 1", "Bloodmoon.bsa", ini);
}
category = "General"; std::ofstream inistream(ini_path.c_str());
{ inistream << ini;
setting = "Werewolf FOV"; add_setting(category, setting, get_setting(category, setting, inx), ini); inistream.close();
} }
category = "Moons";
{ void installToPath(const bfs::path& from, const bfs::path& to, bool copy = false)
setting = "Script Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
}
category = "Weather";
{
setting = "Snow Ripples"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Ripple Radius"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Ripples Per Flake"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Ripple Scale"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Ripple Speed"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Gravity Scale"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow High Kill"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Low Kill"; add_setting(category, setting, get_setting(category, setting, inx), ini);
}
category = "Weather Blight";
{
setting = "Ambient Loop Sound ID"; add_setting(category, setting, get_setting(category, setting, inx), ini);
}
category = "Weather Snow";
{
setting = "Sky Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sky Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sky Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sky Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Disc Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Transition Delta"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Land Fog Day Depth"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Land Fog Night Depth"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Clouds Maximum Percent"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Wind Speed"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Cloud Speed"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Glare View"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Cloud Texture"; 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 = "Snow Threshold"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Diameter"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Height Min"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Height Max"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Snow Entrance Speed"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Max Snowflakes"; add_setting(category, setting, get_setting(category, setting, inx), ini);
}
category = "Weather Blizzard";
{ {
setting = "Sky Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini); make_sure_directory_exists(to);
setting = "Sky Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sky Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sky Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Fog Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Ambient Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Sunrise Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Day Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Night Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Sun Disc Sunset Color"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Transition Delta"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Land Fog Day Depth"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Land Fog Night Depth"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Clouds Maximum Percent"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Wind Speed"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Cloud Speed"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Glare View"; add_setting(category, setting, get_setting(category, setting, inx), ini);
setting = "Cloud Texture"; 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);
}
}
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());
}
}
}
void fix_ini(const bfs::path& output_dir, bfs::path cdPath, bool tribunal, bool bloodmoon) bfs::path findFile(const bfs::path& in, std::string filename, bool recursive = true)
{ {
bfs::path ini_path = output_dir; if(recursive)
ini_path /= "Morrowind.ini"; {
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();
}
}
std::string ini = read_to_string(ini_path.string()); return "";
}
if(tribunal) bool contains(const bfs::path& in, std::string filename)
{ {
add_setting("Game Files", "GameFile1", "Tribunal.esm", ini); for(bfs::directory_iterator end, dir(in); dir != end; ++dir)
add_setting("Archives", "Archive 0", "Tribunal.bsa", ini); {
if(Misc::StringUtils::lowerCase(dir->path().filename().string()) == filename)
return true;
}
return false;
} }
if(bloodmoon)
time_t getTime(const char* time)
{ {
bloodmoon_fix_ini(ini, cdPath / "setup.inx"); struct tm tms;
add_setting("Game Files", "GameFile2", "Bloodmoon.esm", ini); memset(&tms, 0, sizeof(struct tm));
add_setting("Archives", "Archive 1", "Bloodmoon.bsa", ini); strptime(time, "%d %B %Y", &tms);
return mktime(&tms);
} }
std::ofstream inistream(ini_path.c_str());
inistream << ini;
inistream.close();
} }
bool UnshieldThread::SetMorrowindPath(const std::string& path) bool UnshieldThread::SetMorrowindPath(const std::string& path)
@ -300,57 +296,72 @@ 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(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 (prefix && prefix[0])
{ dirname /= prefix;
if(recursive)
if (directory >= 0)
{ {
for ( bfs::recursive_directory_iterator end, dir(in); dir != end; ++dir ) const char* tmp = unshield_directory_name(unshield, directory);
{ if (tmp && tmp[0])
if(Misc::StringUtils::lowerCase(dir->path().filename().string()) == filename) fill_path(dirname, tmp);
return dir->path();
}
} }
else
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)
{ {
for ( bfs::recursive_directory_iterator end, dir(in); dir != end; ++dir ) case FORMAT_NEW:
{ success = unshield_file_save(unshield, index, filename.c_str());
if(Misc::StringUtils::lowerCase(dir->path().filename().string()) == filename) break;
return dir->path(); 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;
} }
return ""; if (!success)
bfs::remove(filename);
return success;
} }
bool contains(const bfs::path& in, std::string filename) void UnshieldThread::extract_cab(const bfs::path& cab, const bfs::path& output_dir, bool extract_ini)
{ {
for(bfs::directory_iterator end, dir(in); dir != end; ++dir) Unshield * unshield;
unshield = unshield_open_force_version(cab.c_str(), -1);
int i;
for (i = 0; i < unshield_file_group_count(unshield); i++)
{ {
if(Misc::StringUtils::lowerCase(dir->path().filename().string()) == filename) UnshieldFileGroup* file_group = unshield_file_group_get(unshield, i);
return true;
}
return false; 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 UnshieldThread::extract() bool UnshieldThread::extract()
{ {
bfs::path outputDataFilesDir = mOutputPath; bfs::path outputDataFilesDir = mOutputPath;
@ -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…
Cancel
Save