implement saving of md5translate.trs
This commit is contained in:
@@ -1606,6 +1606,7 @@ void MapView::saveMinimap(MinimapRenderSettings* settings)
|
||||
if (mmap_render_success)
|
||||
{
|
||||
saving_minimap = false;
|
||||
_world->mapIndex.saveMinimapMD5translate();
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1640,6 +1641,7 @@ void MapView::saveMinimap(MinimapRenderSettings* settings)
|
||||
saving_minimap = false;
|
||||
mmap_render_index = 0;
|
||||
mmap_render_success = false;
|
||||
_world->mapIndex.saveMinimapMD5translate();
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1688,6 +1690,7 @@ void MapView::saveMinimap(MinimapRenderSettings* settings)
|
||||
saving_minimap = false;
|
||||
mmap_render_index = 0;
|
||||
mmap_render_success = false;
|
||||
_world->mapIndex.saveMinimapMD5translate();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include <QtWidgets/QMessageBox>
|
||||
#include <QDir>
|
||||
@@ -2203,7 +2204,8 @@ bool World::saveMinimap(tile_index const& tile_idx, MinimapRenderSettings* setti
|
||||
uint32_t file_size;
|
||||
void* blp_image = blp.createBlpDxtInMemory(true, FORMAT_DXT5, file_size);
|
||||
|
||||
QFile file(dir.filePath(std::string(basename + "_" + std::to_string(tile_idx.x) + "_" + std::to_string(tile_idx.z) + ".blp").c_str()));
|
||||
std::string tex_name = std::string(basename + "_" + std::to_string(tile_idx.x) + "_" + std::to_string(tile_idx.z) + ".blp");
|
||||
QFile file(dir.filePath(tex_name.c_str()));
|
||||
file.open(QIODevice::WriteOnly);
|
||||
QDataStream out(&file);
|
||||
|
||||
@@ -2211,6 +2213,11 @@ bool World::saveMinimap(tile_index const& tile_idx, MinimapRenderSettings* setti
|
||||
|
||||
file.close();
|
||||
|
||||
// Register in md5translate.trs
|
||||
std::string map_name = gMapDB.getMapName(mapIndex._map_id);
|
||||
std::string tilename_left = (boost::format("%s\\map_%d_%02d.blp") % map_name % tile_idx.x % tile_idx.z).str();
|
||||
mapIndex._minimap_md5translate[map_name][tilename_left] = tex_name;
|
||||
|
||||
// image.save(dir.filePath(std::string(basename + "_" + std::to_string(tile_idx.x) + "_" + std::to_string(tile_idx.z) + ".png").c_str()));
|
||||
|
||||
if (unload)
|
||||
|
||||
@@ -14,10 +14,15 @@
|
||||
#include <noggit/uid_storage.hpp>
|
||||
|
||||
#include <QtCore/QSettings>
|
||||
#include <QByteArray>
|
||||
#include <QTextStream>
|
||||
#include <QRegExp>
|
||||
#include <QFile>
|
||||
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
|
||||
#include <forward_list>
|
||||
#include <cstdlib>
|
||||
|
||||
MapIndex::MapIndex (const std::string &pBasename, int map_id, World* world)
|
||||
: basename(pBasename)
|
||||
@@ -136,6 +141,8 @@ MapIndex::MapIndex (const std::string &pBasename, int map_id, World* world)
|
||||
// -----------------------------------------------------
|
||||
|
||||
theFile.close();
|
||||
|
||||
loadMinimapMD5translate();
|
||||
}
|
||||
|
||||
void MapIndex::saveall (World* world)
|
||||
@@ -959,4 +966,89 @@ void MapIndex::loadMaxUID()
|
||||
saveMaxUID();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void MapIndex::loadMinimapMD5translate()
|
||||
{
|
||||
if (!MPQFile::exists("textures/minimap/md5translate.trs"))
|
||||
{
|
||||
LogError << "md5translate.trs was not found. "
|
||||
"Noggit will generate a new one in the project directory on minimap save." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
MPQFile md5trs_file("textures/minimap/md5translate.trs");
|
||||
|
||||
size_t size = md5trs_file.getSize();
|
||||
void* buffer_raw = std::malloc(size);
|
||||
md5trs_file.read(buffer_raw, size);
|
||||
|
||||
QByteArray md5trs_bytes(static_cast<char*>(buffer_raw), size);
|
||||
|
||||
QTextStream md5trs_stream(md5trs_bytes, QIODevice::ReadOnly);
|
||||
|
||||
QString cur_dir = "";
|
||||
while (!md5trs_stream.atEnd())
|
||||
{
|
||||
QString line = md5trs_stream.readLine();
|
||||
|
||||
if (!line.length())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.startsWith("dir: ", Qt::CaseInsensitive))
|
||||
{
|
||||
QStringList dir_line_split = line.split(" ");
|
||||
cur_dir = dir_line_split[1];
|
||||
continue;
|
||||
}
|
||||
|
||||
QStringList line_split = line.split(QRegExp("[\t]"));
|
||||
|
||||
if (cur_dir.length())
|
||||
{
|
||||
_minimap_md5translate[cur_dir.toStdString()][line_split[0].toStdString()] = line_split[1].toStdString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MapIndex::saveMinimapMD5translate()
|
||||
{
|
||||
QSettings settings;
|
||||
QString str = settings.value ("project/path").toString();
|
||||
if (!(str.endsWith('\\') || str.endsWith('/')))
|
||||
{
|
||||
str += "/";
|
||||
}
|
||||
|
||||
QString filepath = str + "/textures/minimap/md5translate.trs";
|
||||
|
||||
QFile file = QFile(filepath);
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text | QFile::Truncate))
|
||||
{
|
||||
QTextStream out(&file);
|
||||
|
||||
for (auto it = _minimap_md5translate.begin(); it != _minimap_md5translate.end(); ++it)
|
||||
{
|
||||
out << "dir: " << it->first.c_str() << "\n"; // save dir
|
||||
|
||||
for (auto it_ = it->second.begin(); it_ != it->second.end(); ++it_)
|
||||
{
|
||||
out << it_->first.c_str() << "\t" << it_->second.c_str() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogError << "Failed saving md5translate.trs. File can't be opened." << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
enum class uid_fix_status
|
||||
@@ -209,6 +210,9 @@ public:
|
||||
return _uid_fix_all_in_progress;
|
||||
}
|
||||
|
||||
void loadMinimapMD5translate();
|
||||
void saveMinimapMD5translate();
|
||||
|
||||
private:
|
||||
uint32_t getHighestGUIDFromFile(const std::string& pFilename) const;
|
||||
|
||||
@@ -218,6 +222,7 @@ private:
|
||||
|
||||
public:
|
||||
int const _map_id;
|
||||
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> _minimap_md5translate;
|
||||
|
||||
private:
|
||||
std::string globalWMOName;
|
||||
@@ -231,6 +236,7 @@ private:
|
||||
bool mHasAGlobalWMO;
|
||||
bool noadt;
|
||||
bool changed;
|
||||
|
||||
bool _sort_models_by_size_class;
|
||||
|
||||
bool autoheight;
|
||||
|
||||
Reference in New Issue
Block a user