Created
December 24, 2016 18:41
-
-
Save Dramacydal/976bc827ba2a677cfb76b1787b3cdbe5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/games/wow/CASCFolder.cpp b/src/games/wow/CASCFolder.cpp | |
index 3b6dfbc..751a8cf 100644 | |
--- a/src/games/wow/CASCFolder.cpp | |
+++ b/src/games/wow/CASCFolder.cpp | |
@@ -191,6 +191,8 @@ void CASCFolder::initVersion() | |
else | |
LOG_INFO << "Version successfully found :" << m_version; | |
+ file.close(); | |
+ | |
} | |
bool CASCFolder::fileExists(std::string file) | |
diff --git a/src/games/wow/GameFolder.cpp b/src/games/wow/GameFolder.cpp | |
index 504385e..f233d3d 100644 | |
--- a/src/games/wow/GameFolder.cpp | |
+++ b/src/games/wow/GameFolder.cpp | |
@@ -17,6 +17,10 @@ | |
#include "logger/Logger.h" | |
+#ifndef SLASH | |
+# define SLASH "/" | |
+#endif | |
+ | |
GameFolder::GameFolder() | |
{ | |
} | |
@@ -39,11 +43,13 @@ void GameFolder::init(const QString & path, const QString & filename) | |
{ | |
QString line = in.readLine().toLower(); | |
- CASCFile * file = new CASCFile(line); | |
- file->setName(line.mid(line.lastIndexOf("\\")+1)); | |
- addChild(file); | |
+ CASCFile * cFile = new CASCFile(line); | |
+ cFile->setName(line.mid(line.lastIndexOf("\\")+1)); | |
+ addChild(cFile); | |
} | |
LOG_INFO << "GameFolder - Hierarchy creation done"; | |
+ | |
+ file.close(); | |
} | |
void GameFolder::addCustomFiles(const QString & path, bool bypassOriginalFiles) | |
@@ -51,11 +57,73 @@ void GameFolder::addCustomFiles(const QString & path, bool bypassOriginalFiles) | |
LOG_INFO << "Add customFiles from folder" << path; | |
QDirIterator dirIt(path, QDirIterator::Subdirectories); | |
+ QString tmpPath = path; | |
+ tmpPath.replace('\\', '/'); | |
+ | |
+ std::vector<QString> allowedDirectories = | |
+ { | |
+ tmpPath + SLASH + "Character", | |
+ tmpPath + SLASH + "Creature", | |
+ tmpPath + SLASH + "Dungeons", | |
+ tmpPath + SLASH + "Interface", | |
+ tmpPath + SLASH + "Item", | |
+ tmpPath + SLASH + "Textures", | |
+ tmpPath + SLASH + "World" | |
+ }; | |
+ | |
+ std::vector<QString> forbiddenDirectories = | |
+ { | |
+ tmpPath + SLASH + "Interface" + SLASH + "Addons", | |
+ }; | |
+ | |
+ for (auto& allowed : allowedDirectories) | |
+ LOG_INFO << "Allowed: " << allowed; | |
+ | |
+ for (auto& forbidden : forbiddenDirectories) | |
+ LOG_INFO << "Forbidden: " << forbidden; | |
+ | |
while(dirIt.hasNext()) | |
{ | |
dirIt.next(); | |
QString filePath = dirIt.filePath().toLower(); | |
+ //if (QFileInfo(filePath).isDir()) | |
+ { | |
+ auto needContinue = false; | |
+ for (auto& forbidden : forbiddenDirectories) | |
+ { | |
+ if (filePath == forbidden.toLower() || | |
+ filePath.startsWith(forbidden.toLower() + SLASH)) | |
+ { | |
+ needContinue = true; | |
+ break; | |
+ } | |
+ } | |
+ | |
+ if (needContinue) | |
+ { | |
+ LOG_INFO << "Skipping \"" << filePath << "\" as it is in list of forbidden directories"; | |
+ continue; | |
+ } | |
+ | |
+ needContinue = true; | |
+ for (auto& allowed : allowedDirectories) | |
+ { | |
+ if (filePath == allowed.toLower() || | |
+ filePath.startsWith(allowed.toLower() + SLASH)) | |
+ { | |
+ needContinue = false; | |
+ break; | |
+ } | |
+ } | |
+ | |
+ if (needContinue) | |
+ { | |
+ LOG_INFO << "Skipping \"" << filePath << "\" as it is not in list of allowed directories"; | |
+ continue; | |
+ } | |
+ } | |
+ | |
if(QFileInfo(filePath).isFile()) | |
{ | |
QString toRemove = path; | |
@@ -79,7 +147,7 @@ void GameFolder::addCustomFiles(const QString & path, bool bypassOriginalFiles) | |
} | |
} | |
- if(addnewfile) | |
+ if (addnewfile) | |
{ | |
LOG_INFO << "Add custom file" << filePath << "from hard drive location" << dirIt.filePath(); | |
HardDriveFile * file = new HardDriveFile(filePath, dirIt.filePath()); | |
diff --git a/src/games/wow/HardDriveFile.cpp b/src/games/wow/HardDriveFile.cpp | |
index 3db9c99..dd876f2 100644 | |
--- a/src/games/wow/HardDriveFile.cpp | |
+++ b/src/games/wow/HardDriveFile.cpp | |
@@ -8,12 +8,14 @@ | |
#include "HardDriveFile.h" | |
#include <QFile> | |
+#include <QFileInfo> | |
+#include <QDateTime> | |
#include "logger/Logger.h" | |
HardDriveFile::HardDriveFile(QString path, QString real) | |
- : GameFile(path), opened(false), realpath(real) | |
+ : GameFile(path), opened(false), realpath(real), ModifyTimeStamp(0) | |
{ | |
} | |
@@ -22,21 +24,38 @@ HardDriveFile::~HardDriveFile() | |
close(); | |
} | |
- | |
+#define DEBUG_READ 1 | |
bool HardDriveFile::open() | |
{ | |
#ifdef DEBUG_READ | |
LOG_INFO << __FUNCTION__ << "Opening" << filepath; | |
#endif | |
+ QFileInfo info(realpath); | |
+ if (!info.exists()) | |
+ { | |
+ LOG_INFO << "No such file: " << realpath; | |
+ return false; | |
+ } | |
+ | |
if(opened) | |
{ | |
#ifdef DEBUG_READ | |
LOG_INFO << filepath << "is already opened"; | |
#endif | |
- return true; | |
+ | |
+ if (info.lastModified().toTime_t() != ModifyTimeStamp) | |
+ { | |
+ opened = false; | |
+ delete[] buffer; | |
+ LOG_INFO << "File " << realpath << " is already opened, but it's modify time has changed, reopening"; | |
+ } | |
+ else | |
+ return true; | |
} | |
+ ModifyTimeStamp = info.lastModified().toTime_t(); | |
+ | |
eof = true; | |
QFile file(realpath); | |
if(!file.open(QIODevice::ReadOnly)) | |
@@ -80,5 +99,8 @@ bool HardDriveFile::close() | |
opened = false; | |
} | |
+ delete[] buffer; | |
+ buffer = NULL; | |
+ | |
return true; | |
} | |
diff --git a/src/games/wow/HardDriveFile.h b/src/games/wow/HardDriveFile.h | |
index 9a42946..cf4c9cc 100644 | |
--- a/src/games/wow/HardDriveFile.h | |
+++ b/src/games/wow/HardDriveFile.h | |
@@ -32,6 +32,7 @@ class _HARDDRIVEFILE_API_ HardDriveFile : public GameFile | |
private: | |
bool opened; | |
QString realpath; | |
+ uint ModifyTimeStamp; | |
}; | |
diff --git a/src/games/wow/WoWItem.cpp b/src/games/wow/WoWItem.cpp | |
index ab659f7..02ef1fb 100644 | |
--- a/src/games/wow/WoWItem.cpp | |
+++ b/src/games/wow/WoWItem.cpp | |
@@ -1077,4 +1077,6 @@ void WoWItem::load(QString & f) | |
load(); // refresh tabard textures | |
} | |
} | |
+ | |
+ file.close(); | |
} | |
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt | |
index 6e6973c..2bb1c3f 100644 | |
--- a/src/plugins/CMakeLists.txt | |
+++ b/src/plugins/CMakeLists.txt | |
@@ -4,4 +4,4 @@ add_subdirectory(importers/wowhead) | |
#exporters | |
add_subdirectory(exporters/obj) | |
-add_subdirectory(exporters/fbx) | |
+#add_subdirectory(exporters/fbx) | |
diff --git a/src/wowmodelviewer/enums.h b/src/wowmodelviewer/enums.h | |
index 07868fd..64ad8b0 100644 | |
--- a/src/wowmodelviewer/enums.h | |
+++ b/src/wowmodelviewer/enums.h | |
@@ -219,6 +219,7 @@ enum ObjectID { | |
ID_MODEL_PC_START_13, | |
ID_MODEL_PC_MID_13, | |
ID_MODEL_PC_END_13, | |
+ ID_TEXTURE_LIST, | |
// ---------------------------------------- | |
// Model Bank Control Frame | |
@@ -285,6 +286,8 @@ enum ObjectID { | |
ID_MOUNT, | |
+ ID_RELOAD_CUSTOM_FILELIST, | |
+ | |
ID_EQUIPMENT = 5000 | |
}; | |
diff --git a/src/wowmodelviewer/filecontrol.cpp b/src/wowmodelviewer/filecontrol.cpp | |
index a9dffe0..6b4a4d9 100644 | |
--- a/src/wowmodelviewer/filecontrol.cpp | |
+++ b/src/wowmodelviewer/filecontrol.cpp | |
@@ -23,6 +23,7 @@ BEGIN_EVENT_TABLE(FileControl, wxWindow) | |
EVT_TEXT_ENTER(ID_FILELIST_CONTENT, FileControl::OnButton) | |
EVT_CHOICE(ID_FILELIST_FILTER, FileControl::OnChoice) | |
EVT_TREE_ITEM_MENU(ID_FILELIST, FileControl::OnTreeMenu) | |
+ EVT_BUTTON(ID_RELOAD_CUSTOM_FILELIST, FileControl::ReloadCustomFileList) | |
END_EVENT_TABLE() | |
enum FilterModes { | |
@@ -86,6 +87,8 @@ FileControl::FileControl(wxWindow* parent, wxWindowID id) | |
fileTree = new wxTreeCtrl(this, ID_FILELIST, wxPoint(0, 35), wxSize(250,580), wxTR_HIDE_ROOT|wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT|wxTR_FULL_ROW_HIGHLIGHT|wxTR_NO_LINES); | |
choFilter = new wxChoice(this, ID_FILELIST_FILTER, wxPoint(10, 620), wxSize(130, 10), WXSIZEOF(chos), chos); | |
choFilter->SetSelection(filterMode); | |
+ textureList = new wxTextCtrl(this, ID_TEXTURE_LIST, wxEmptyString, wxPoint(10,660), wxSize(250,150), wxTE_MULTILINE | wxTE_DONTWRAP); | |
+ reloadCustomFiles = new wxButton(this, ID_RELOAD_CUSTOM_FILELIST, _("Reload Custom Files"), wxPoint(10, 820), wxSize(110,25)); | |
} catch(...) {}; | |
} | |
@@ -174,6 +177,7 @@ void FileControl::OnChoice(wxCommandEvent &event) | |
if (curSelection >= 0 && curSelection != filterMode) { | |
filterMode = curSelection; | |
Init(); | |
+ UpdateTextureInfo(); | |
} | |
} | |
} | |
@@ -463,6 +467,7 @@ void FileControl::UpdateInterface() | |
// Update the layout | |
modelviewer->interfaceManager.Update(); | |
+ modelviewer->fileControl->UpdateTextureInfo(); | |
} | |
void FileControl::OnTreeSelect(wxTreeEvent &event) | |
@@ -495,11 +500,14 @@ void FileControl::OnTreeSelect(wxTreeEvent &event) | |
// Check to make sure the selected item is a model (an *.m2 file). | |
modelviewer->isModel = (rootfn.Last() == '2'); | |
+ auto selectedFile = GAMEDIRECTORY.getFile(rootfn.c_str()); | |
+ LOG_INFO << "Selected: " << rootfn.c_str() << " " << selectedFile; | |
+ | |
// not functional yet. | |
//if (wxGetKeyState(WXK_SHIFT)) | |
// canvas->AddModel(rootfn); | |
//else | |
- modelviewer->LoadModel(GAMEDIRECTORY.getFile(rootfn.c_str())); // Load the model. | |
+ modelviewer->LoadModel(selectedFile); // Load the model. | |
UpdateInterface(); | |
} else if (filterMode == FILE_FILTER_WMO) { | |
@@ -593,5 +601,33 @@ void FileControl::OnButton(wxCommandEvent &event) | |
} | |
} | |
+void FileControl::ReloadCustomFileList(wxCommandEvent&) | |
+{ | |
+ if(!customDirectoryPath.IsEmpty()) | |
+ Game::instance().addCustomFiles(QString(customDirectoryPath.c_str()), customFilesConflictPolicy); | |
+} | |
- | |
+void FileControl::UpdateTextureInfo() | |
+{ | |
+ QString str = ""; | |
+ if (modelviewer->canvas->model) | |
+ { | |
+ auto textures = modelviewer->canvas->model->TextureList; | |
+ for (int i = 0; i < textures.size(); ++i) | |
+ { | |
+ GameFile* file = textures[i]; | |
+ str += file->fullname() + "\n"; | |
+ } | |
+ } | |
+ if (modelviewer->canvas->wmo) | |
+ { | |
+ auto textures = modelviewer->canvas->wmo->textures; | |
+ for (auto& texture : textures) | |
+ { | |
+ str += texture + "\n"; | |
+ } | |
+ } | |
+ | |
+ textureList->Clear(); | |
+ textureList->AppendText(_(str.toStdString().c_str())); | |
+} | |
diff --git a/src/wowmodelviewer/filecontrol.h b/src/wowmodelviewer/filecontrol.h | |
index 489ab28..73d39c0 100644 | |
--- a/src/wowmodelviewer/filecontrol.h | |
+++ b/src/wowmodelviewer/filecontrol.h | |
@@ -35,11 +35,16 @@ public: | |
void Export(wxString val, int select); | |
wxString ExportPNG(wxString val); | |
void UpdateInterface(); | |
+ void UpdateTextureInfo(); | |
+ void ReloadCustomFileList(wxCommandEvent &event); | |
wxTreeCtrl *fileTree; | |
wxButton *btnSearch; | |
wxTextCtrl *txtContent; | |
wxChoice *choFilter; | |
+ wxButton *textureInfoButton; | |
+ wxTextCtrl *textureList; | |
+ wxButton* reloadCustomFiles; | |
int filterMode; | |
wxTreeItemId CurrentItem; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment