summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2014-11-21 15:07:31 +0100
committerTannin <devnull@localhost>2014-11-21 15:07:31 +0100
commit45a46778fb9c7195cb09fbba4a2c502dca6bca13 (patch)
treec304a6ffa3412fa66edab50fd293cc7fd13faaa9 /src/shared
parentcfb863f6c3ae7406028b9e167a3115250fefbca3 (diff)
parentf2f9e11fdd876821107cff0c1c5b9d8ecf66691f (diff)
Merge
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/directoryentry.cpp20
-rw-r--r--src/shared/directoryentry.h4
-rw-r--r--src/shared/fallout3info.cpp25
-rw-r--r--src/shared/fallout3info.h8
-rw-r--r--src/shared/falloutnvinfo.cpp62
-rw-r--r--src/shared/falloutnvinfo.h8
-rw-r--r--src/shared/gameinfo.cpp40
-rw-r--r--src/shared/gameinfo.h10
-rw-r--r--src/shared/leaktrace.cpp2
-rw-r--r--src/shared/oblivioninfo.cpp25
-rw-r--r--src/shared/oblivioninfo.h8
-rw-r--r--src/shared/shared.pro53
-rw-r--r--src/shared/skyriminfo.cpp57
-rw-r--r--src/shared/skyriminfo.h10
-rw-r--r--src/shared/util.cpp36
15 files changed, 170 insertions, 198 deletions
diff --git a/src/shared/directoryentry.cpp b/src/shared/directoryentry.cpp
index e0914870..0adf0812 100644
--- a/src/shared/directoryentry.cpp
+++ b/src/shared/directoryentry.cpp
@@ -72,8 +72,7 @@ public:
}
bool exists(const std::wstring &name) {
- std::map<std::wstring, int>::iterator iter = m_OriginsNameMap.find(name);
- return iter != m_OriginsNameMap.end();
+ return m_OriginsNameMap.find(name) != m_OriginsNameMap.end();
}
FilesOrigin &getByID(Index ID) {
@@ -325,13 +324,13 @@ static bool ByOriginPriority(DirectoryEntry *entry, int LHS, int RHS)
FileEntry::FileEntry()
- : m_Index(UINT_MAX), m_Name(), m_Parent(NULL), m_LastAccessed(time(NULL))
+ : m_Index(UINT_MAX), m_Name(), m_Origin(-1), m_Parent(NULL), m_LastAccessed(time(NULL))
{
LEAK_TRACE;
}
FileEntry::FileEntry(Index index, const std::wstring &name, DirectoryEntry *parent)
- : m_Index(index), m_Name(name), m_Parent(parent), m_Origin(-1), m_Archive(L""), m_LastAccessed(time(NULL))
+ : m_Index(index), m_Name(name), m_Origin(-1), m_Parent(parent), m_Archive(L""), m_LastAccessed(time(NULL))
{
LEAK_TRACE;
}
@@ -369,16 +368,14 @@ std::wstring FileEntry::getFullPath() const
bool ignore = false;
result = m_Parent->getOriginByID(getOrigin(ignore)).getPath(); //base directory for origin
recurseParents(result, m_Parent); // all intermediate directories
- result.append(L"\\").append(m_Name); // the actual filename
- return result;
+ return result + L"\\" + m_Name;
}
std::wstring FileEntry::getRelativePath() const
{
std::wstring result;
recurseParents(result, m_Parent); // all intermediate directories
- result.append(L"\\").append(m_Name); // the actual filename
- return result;
+ return result + L"\\" + m_Name;
}
@@ -446,6 +443,7 @@ void DirectoryEntry::addFromOrigin(const std::wstring &originName, const std::ws
boost::scoped_array<wchar_t> buffer(new wchar_t[MAXPATH_UNICODE + 1]);
memset(buffer.get(), L'\0', MAXPATH_UNICODE + 1);
int offset = _snwprintf(buffer.get(), MAXPATH_UNICODE, L"%ls", directory.c_str());
+ buffer.get()[offset] = L'\0';
addFiles(origin, buffer.get(), offset);
}
m_Populated = true;
@@ -636,7 +634,7 @@ void DirectoryEntry::insertFile(const std::wstring &filePath, FilesOrigin &origi
void DirectoryEntry::removeFile(FileEntry::Index index)
{
- if (m_Files.size() != 0) {
+ if (!m_Files.empty()) {
auto iter = std::find_if(m_Files.begin(), m_Files.end(),
[&index](const std::pair<std::wstring, FileEntry::Index> &iter) -> bool {
return iter.second == index; } );
@@ -936,10 +934,6 @@ void FileRegister::removeOriginMulti(std::set<FileEntry::Index> indices, int ori
}
}
- if (removedFiles.size() > 0) {
- log("%d files actually removed", removedFiles.size());
- }
-
// optimization: this is only called when disabling an origin and in this case we don't have
// to remove the file from the origin
diff --git a/src/shared/directoryentry.h b/src/shared/directoryentry.h
index 7836d719..d588ab02 100644
--- a/src/shared/directoryentry.h
+++ b/src/shared/directoryentry.h
@@ -29,8 +29,10 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#define WIN32_MEAN_AND_LEAN
#include <Windows.h>
#include <bsatk.h>
+#ifndef Q_MOC_RUN
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
+#endif
#include "util.h"
@@ -217,7 +219,7 @@ public:
void clear();
bool isPopulated() const { return m_Populated; }
- bool isEmpty() const { return (m_Files.size() == 0) && (m_SubDirectories.size() == 0); }
+ bool isEmpty() const { return m_Files.empty() && m_SubDirectories.empty(); }
const DirectoryEntry *getParent() const { return m_Parent; }
diff --git a/src/shared/fallout3info.cpp b/src/shared/fallout3info.cpp
index 9487d2de..82b285b7 100644
--- a/src/shared/fallout3info.cpp
+++ b/src/shared/fallout3info.cpp
@@ -54,15 +54,17 @@ std::wstring Fallout3Info::getRegPathStatic()
0, KEY_QUERY_VALUE, &key);
if (errorcode != ERROR_SUCCESS) {
- return L"";
+ return std::wstring();
}
WCHAR temp[MAX_PATH];
DWORD bufferSize = MAX_PATH;
- errorcode = ::RegQueryValueExW(key, L"Installed Path", NULL, NULL, (LPBYTE)temp, &bufferSize);
-
- return std::wstring(temp);
+ if (::RegQueryValueExW(key, L"Installed Path", NULL, NULL, (LPBYTE)temp, &bufferSize) == ERROR_SUCCESS) {
+ return std::wstring(temp);
+ } else {
+ return std::wstring();
+ }
}
std::wstring Fallout3Info::getInvalidationBSA()
@@ -233,15 +235,12 @@ void Fallout3Info::createProfile(const std::wstring &directory, bool useDefaults
}
}
{ // copy falloutprefs.ini-file
- std::wstring target = directory.substr().append(L"\\falloutprefs.ini");
+ std::wstring target = directory + L"\\falloutprefs.ini";
if (!FileExists(target)) {
- std::wostringstream source;
- source << getMyGamesDirectory() << L"\\Fallout3\\falloutprefs.ini";
- if (!::CopyFileW(source.str().c_str(), target.c_str(), true)) {
+ std::wstring source = getMyGamesDirectory() + L"\\Fallout3\\falloutprefs.ini";
+ if (!::CopyFileW(source.c_str(), target.c_str(), true)) {
if (::GetLastError() != ERROR_FILE_EXISTS) {
- std::ostringstream stream;
- stream << "failed to copy ini file: " << ToString(source.str(), false);
- throw windows_error(stream.str());
+ throw windows_error(std::string("failed to copy ini file: ") + ToString(source, false));
}
}
}
@@ -268,7 +267,7 @@ bool Fallout3Info::rerouteToProfile(const wchar_t *fileName, const wchar_t*)
}
-std::vector<ExecutableInfo> Fallout3Info::getExecutables()
+/*std::vector<ExecutableInfo> Fallout3Info::getExecutables()
{
std::vector<ExecutableInfo> result;
result.push_back(ExecutableInfo(L"FOSE", L"fose_loader.exe", L"", L"", DEFAULT_CLOSE));
@@ -279,5 +278,5 @@ std::vector<ExecutableInfo> Fallout3Info::getExecutables()
result.push_back(ExecutableInfo(L"BOSS", L"BOSS/BOSS.exe", L"", L"", NEVER_CLOSE));
return result;
-}
+}*/
} // namespace MOShared
diff --git a/src/shared/fallout3info.h b/src/shared/fallout3info.h
index 8e4c260d..7e39cce4 100644
--- a/src/shared/fallout3info.h
+++ b/src/shared/fallout3info.h
@@ -38,7 +38,7 @@ public:
virtual unsigned long getBSAVersion();
static std::wstring getRegPathStatic();
- virtual std::wstring getRegPath() { return Fallout3Info::getRegPathStatic(); }
+ virtual std::wstring getRegPath() { return getRegPathStatic(); }
virtual std::wstring getBinaryName() { return L"Fallout3.exe"; }
virtual GameInfo::Type getType() { return TYPE_FALLOUT3; }
@@ -75,9 +75,9 @@ public:
virtual std::wstring getNexusPage(bool nmmScheme = true);
static std::wstring getNexusInfoUrlStatic();
- virtual std::wstring getNexusInfoUrl() { return Fallout3Info::getNexusInfoUrlStatic(); }
+ virtual std::wstring getNexusInfoUrl() { return getNexusInfoUrlStatic(); }
static int getNexusModIDStatic();
- virtual int getNexusModID() { return Fallout3Info::getNexusModIDStatic(); }
+ virtual int getNexusModID() { return getNexusModIDStatic(); }
virtual int getNexusGameID() { return 120; }
virtual void createProfile(const std::wstring &directory, bool useDefaults);
@@ -87,7 +87,7 @@ public:
// get a list of executables (game binary and known-to-work 3rd party tools). All of these are relative to
// the game directory
- virtual std::vector<ExecutableInfo> getExecutables();
+ //virtual std::vector<ExecutableInfo> getExecutables();
virtual std::wstring archiveListKey() { return L"SArchiveList"; }
diff --git a/src/shared/falloutnvinfo.cpp b/src/shared/falloutnvinfo.cpp
index 9bba7fe4..178ce8b4 100644
--- a/src/shared/falloutnvinfo.cpp
+++ b/src/shared/falloutnvinfo.cpp
@@ -55,15 +55,17 @@ std::wstring FalloutNVInfo::getRegPathStatic()
0, KEY_QUERY_VALUE, &key);
if (errorcode != ERROR_SUCCESS) {
- return L"";
+ return std::wstring();
}
WCHAR temp[MAX_PATH];
DWORD bufferSize = MAX_PATH;
- errorcode = ::RegQueryValueExW(key, L"Installed Path", NULL, NULL, (LPBYTE)temp, &bufferSize);
-
- return std::wstring(temp);
+ if (::RegQueryValueExW(key, L"Installed Path", NULL, NULL, (LPBYTE)temp, &bufferSize) == ERROR_SUCCESS) {
+ return std::wstring(temp);
+ } else {
+ return std::wstring();
+ }
}
std::wstring FalloutNVInfo::getInvalidationBSA()
@@ -162,56 +164,46 @@ std::wstring FalloutNVInfo::getSteamAPPId(int) const
void FalloutNVInfo::createProfile(const std::wstring &directory, bool useDefaults)
{
- std::wostringstream target;
+ std::wstring target = directory + L"\\plugins.txt";
// copy plugins.txt
- target << directory << "\\plugins.txt";
-
- if (!FileExists(target.str())) {
- std::wostringstream source;
- source << getLocalAppFolder() << "\\FalloutNV\\plugins.txt";
- if (!::CopyFileW(source.str().c_str(), target.str().c_str(), true)) {
- HANDLE file = ::CreateFileW(target.str().c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (!FileExists(target)) {
+ std::wstring source = getLocalAppFolder() + L"\\FalloutNV\\plugins.txt";
+ if (!::CopyFileW(source.c_str(), target.c_str(), true)) {
+ HANDLE file = ::CreateFileW(target.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
::CloseHandle(file);
}
}
// copy ini-file
- target.str(L""); target.clear();
- target << directory << L"\\fallout.ini";
+ target = directory + L"\\fallout.ini";
- if (!FileExists(target.str())) {
- std::wostringstream source;
+ if (!FileExists(target)) {
+ std::wstring source;
if (useDefaults) {
- source << getGameDirectory() << L"\\fallout_default.ini";
+ source = getGameDirectory() + L"\\fallout_default.ini";
} else {
- source << getMyGamesDirectory() << L"\\FalloutNV";
- if (FileExists(source.str(), L"fallout.ini")) {
- source << L"\\fallout.ini";
+ source = getMyGamesDirectory() + L"\\FalloutNV";
+ if (FileExists(source, L"fallout.ini")) {
+ source += L"\\fallout.ini";
} else {
- source.str(L"");
- source << getGameDirectory() << L"\\fallout_default.ini";
+ source = getGameDirectory() + L"\\fallout_default.ini";
}
}
- if (!::CopyFileW(source.str().c_str(), target.str().c_str(), true)) {
+ if (!::CopyFileW(source.c_str(), target.c_str(), true)) {
if (::GetLastError() != ERROR_FILE_EXISTS) {
- std::ostringstream stream;
- stream << "failed to copy ini file: " << ToString(source.str(), false);
- throw windows_error(stream.str());
+ throw windows_error("failed to copy ini file: " + ToString(source, false));
}
}
}
{ // copy falloutprefs.ini-file
- std::wstring target = directory.substr().append(L"\\falloutprefs.ini");
+ std::wstring target = directory + L"\\falloutprefs.ini";
if (!FileExists(target)) {
- std::wostringstream source;
- source << getMyGamesDirectory() << L"\\FalloutNV\\falloutprefs.ini";
- if (!::CopyFileW(source.str().c_str(), target.c_str(), true)) {
+ std::wstring source = getMyGamesDirectory() + L"\\FalloutNV\\falloutprefs.ini";
+ if (!::CopyFileW(source.c_str(), target.c_str(), true)) {
if (::GetLastError() != ERROR_FILE_EXISTS) {
- std::ostringstream stream;
- stream << "failed to copy ini file: " << ToString(source.str(), false);
- throw windows_error(stream.str());
+ throw windows_error("failed to copy ini file: " + ToString(source, false));
}
}
}
@@ -265,7 +257,7 @@ bool FalloutNVInfo::rerouteToProfile(const wchar_t *fileName, const wchar_t*)
return false;
}
-
+/*
std::vector<ExecutableInfo> FalloutNVInfo::getExecutables()
{
std::vector<ExecutableInfo> result;
@@ -277,5 +269,5 @@ std::vector<ExecutableInfo> FalloutNVInfo::getExecutables()
result.push_back(ExecutableInfo(L"BOSS", L"BOSS/BOSS.exe", L"", L"", NEVER_CLOSE));
return result;
-}
+}*/
} // namespace MOShared
diff --git a/src/shared/falloutnvinfo.h b/src/shared/falloutnvinfo.h
index cfd373c7..231311de 100644
--- a/src/shared/falloutnvinfo.h
+++ b/src/shared/falloutnvinfo.h
@@ -38,7 +38,7 @@ public:
virtual unsigned long getBSAVersion();
static std::wstring getRegPathStatic();
- virtual std::wstring getRegPath() { return FalloutNVInfo::getRegPathStatic(); }
+ virtual std::wstring getRegPath() { return getRegPathStatic(); }
virtual std::wstring getBinaryName() { return L"FalloutNV.exe"; }
virtual GameInfo::Type getType() { return TYPE_FALLOUTNV; }
@@ -76,9 +76,9 @@ public:
virtual std::wstring getNexusPage(bool nmmScheme = true);
static std::wstring getNexusInfoUrlStatic();
- virtual std::wstring getNexusInfoUrl() { return FalloutNVInfo::getNexusInfoUrlStatic(); }
+ virtual std::wstring getNexusInfoUrl() { return getNexusInfoUrlStatic(); }
static int getNexusModIDStatic();
- virtual int getNexusModID() { return FalloutNVInfo::getNexusModIDStatic(); }
+ virtual int getNexusModID() { return getNexusModIDStatic(); }
virtual int getNexusGameID() { return 130; }
virtual void createProfile(const std::wstring &directory, bool useDefaults);
@@ -88,7 +88,7 @@ public:
// get a list of executables (game binary and known-to-work 3rd party tools). All of these are relative to
// the game directory
- virtual std::vector<ExecutableInfo> getExecutables();
+ //virtual std::vector<ExecutableInfo> getExecutables();
virtual std::wstring archiveListKey() { return L"SArchiveList"; }
diff --git a/src/shared/gameinfo.cpp b/src/shared/gameinfo.cpp
index 21e9a586..5439efff 100644
--- a/src/shared/gameinfo.cpp
+++ b/src/shared/gameinfo.cpp
@@ -57,7 +57,7 @@ void GameInfo::identifyMyGamesDirectory(const std::wstring &file)
{
// this function attempts 3 (three!) ways to determine the correct "My Games" folder.
wchar_t myDocuments[MAX_PATH];
- memset(myDocuments, '\0', MAX_PATH);
+ memset(myDocuments, '\0', MAX_PATH * sizeof(wchar_t));
m_MyGamesDirectory.clear();
@@ -137,71 +137,53 @@ std::wstring GameInfo::getGameDirectory() const
std::wstring GameInfo::getModsDir() const
{
- std::wostringstream temp;
- temp << m_OrganizerDataDirectory << L"\\mods";
- return temp.str();
+ return m_OrganizerDirectory + L"\\mods";
}
std::wstring GameInfo::getProfilesDir() const
{
- std::wostringstream temp;
- temp << m_OrganizerDataDirectory << L"\\profiles";
- return temp.str();
+ return m_OrganizerDirectory + L"\\profiles";
}
std::wstring GameInfo::getIniFilename() const
{
- std::wostringstream temp;
- temp << m_OrganizerDataDirectory << L"\\ModOrganizer.ini";
- return temp.str();
+ return m_OrganizerDirectory + L"\\ModOrganizer.ini";
}
std::wstring GameInfo::getDownloadDir() const
{
- std::wostringstream temp;
- temp << m_OrganizerDataDirectory << L"\\downloads";
- return temp.str();
+ return m_OrganizerDirectory + L"\\downloads";
}
std::wstring GameInfo::getCacheDir() const
{
- std::wostringstream temp;
- temp << m_OrganizerDataDirectory << L"\\webcache";
- return temp.str();
+ return m_OrganizerDirectory + L"\\webcache";
}
std::wstring GameInfo::getOverwriteDir() const
{
- std::wostringstream temp;
- temp << m_OrganizerDataDirectory << "\\overwrite";
- return temp.str();
+ return m_OrganizerDirectory + L"\\overwrite";
}
std::wstring GameInfo::getLogDir() const
{
- std::wostringstream temp;
- temp << m_OrganizerDataDirectory << "\\logs";
- return temp.str();
+ return m_OrganizerDirectory + L"\\logs";
}
std::wstring GameInfo::getLootDir() const
{
- std::wostringstream temp;
- temp << m_OrganizerDirectory << "\\loot";
- return temp.str();
+ return m_OrganizerDirectory + L"\\loot";
}
std::wstring GameInfo::getTutorialDir() const
{
- std::wostringstream temp;
- temp << m_OrganizerDirectory << "\\tutorials";
- return temp.str();
+ return m_OrganizerDirectory + L"\\tutorials";
}
@@ -219,7 +201,7 @@ std::vector<std::wstring> GameInfo::getSteamVariants() const
std::wstring GameInfo::getLocalAppFolder() const
{
wchar_t localAppFolder[MAX_PATH];
- memset(localAppFolder, '\0', MAX_PATH);
+ memset(localAppFolder, '\0', MAX_PATH * sizeof(wchar_t));
if (::SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, localAppFolder) == S_OK) {
return localAppFolder;
diff --git a/src/shared/gameinfo.h b/src/shared/gameinfo.h
index d719a073..c11679f3 100644
--- a/src/shared/gameinfo.h
+++ b/src/shared/gameinfo.h
@@ -28,7 +28,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <Windows.h>
namespace MOShared {
-
+/*
enum CloseMOStyle {
DEFAULT_CLOSE,
DEFAULT_STAY,
@@ -53,7 +53,7 @@ struct ExecutableInfo {
CloseMOStyle closeMO;
std::wstring steamAppID;
};
-
+*/
/**
Class to manage information that depends on the used game type. The intention is to keep
@@ -160,13 +160,9 @@ public:
virtual bool rerouteToProfile(const wchar_t *fileName, const wchar_t *fullPath) = 0;
- // get a list of executables (game binary and known-to-work 3rd party tools). All of these are relative to
- // the game directory. the boolean says whether omo should be closed when the executable is started
- virtual std::vector<ExecutableInfo> getExecutables() = 0;
-
public:
- // initialise with the path to the omo directory (needs to be where hook.dll is stored). This
+ // initialise with the path to the mo directory (needs to be where hook.dll is stored). This
// needs to be called before the instance can be retrieved
static bool init(const std::wstring &moDirectory, const std::wstring &moDataDirectory, const std::wstring &gamePath = L"");
diff --git a/src/shared/leaktrace.cpp b/src/shared/leaktrace.cpp
index 68e57609..729eb42e 100644
--- a/src/shared/leaktrace.cpp
+++ b/src/shared/leaktrace.cpp
@@ -36,7 +36,7 @@ class StackData {
public:
StackData()
- : m_FunctionName("Dummy"), m_CodeLine(0)
+ : m_Count(0), m_Hash(0UL), m_FunctionName("Dummy"), m_CodeLine(0)
{}
StackData(const char *functionName, int line) {
m_Count = ::CaptureStackBackTrace(FRAMES_TO_SKIP, FRAMES_TO_CAPTURE, m_Stack, &m_Hash);
diff --git a/src/shared/oblivioninfo.cpp b/src/shared/oblivioninfo.cpp
index f317812f..89a795a5 100644
--- a/src/shared/oblivioninfo.cpp
+++ b/src/shared/oblivioninfo.cpp
@@ -55,15 +55,17 @@ std::wstring OblivionInfo::getRegPathStatic()
0, KEY_QUERY_VALUE, &key);
if (errorcode != ERROR_SUCCESS) {
- return L"";
+ return std::wstring();
}
WCHAR temp[MAX_PATH];
DWORD bufferSize = MAX_PATH;
- errorcode = ::RegQueryValueExW(key, L"Installed Path", NULL, NULL, (LPBYTE)temp, &bufferSize);
-
- return std::wstring(temp);
+ if (::RegQueryValueExW(key, L"Installed Path", NULL, NULL, (LPBYTE)temp, &bufferSize) == ERROR_SUCCESS) {
+ return std::wstring(temp);
+ } else {
+ return std::wstring();
+ }
}
std::wstring OblivionInfo::getInvalidationBSA()
@@ -188,16 +190,13 @@ void OblivionInfo::createProfile(const std::wstring &directory, bool useDefaults
}
{ // copy oblivionprefs.ini-file
- std::wstring target = directory.substr().append(L"\\oblivionprefs.ini");
+ std::wstring target = directory + L"\\oblivionprefs.ini";
if (!FileExists(target)) {
- std::wostringstream source;
- source << getMyGamesDirectory() << L"\\Oblivion\\oblivionprefs.ini";
- if (!::CopyFileW(source.str().c_str(), target.c_str(), true)) {
+ std::wstring source = getMyGamesDirectory() + L"\\Oblivion\\oblivionprefs.ini";
+ if (!::CopyFileW(source.c_str(), target.c_str(), true)) {
if ((::CreateFileW(target.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL) == INVALID_HANDLE_VALUE) &&
(::GetLastError() != ERROR_FILE_EXISTS)) {
- std::ostringstream stream;
- stream << "failed to create ini file: " << ToString(target.c_str(), false);
- throw windows_error(stream.str());
+ throw windows_error(std::string("failed to create ini file: ") + ToString(target, false));
}
}
}
@@ -274,7 +273,7 @@ std::wstring OblivionInfo::getSteamAPPId(int) const
return L"22330";
}
-
+/*
std::vector<ExecutableInfo> OblivionInfo::getExecutables()
{
std::vector<ExecutableInfo> result;
@@ -287,5 +286,5 @@ std::vector<ExecutableInfo> OblivionInfo::getExecutables()
result.push_back(ExecutableInfo(L"BOSS (old)", L"Data/BOSS.exe", L"", L"", NEVER_CLOSE));
return result;
-}
+}*/
} // namespace MOShared
diff --git a/src/shared/oblivioninfo.h b/src/shared/oblivioninfo.h
index 02fd90b4..cb506c01 100644
--- a/src/shared/oblivioninfo.h
+++ b/src/shared/oblivioninfo.h
@@ -36,7 +36,7 @@ public:
virtual unsigned long getBSAVersion();
static std::wstring getRegPathStatic();
- virtual std::wstring getRegPath() { return OblivionInfo::getRegPathStatic(); }
+ virtual std::wstring getRegPath() { return getRegPathStatic(); }
virtual std::wstring getBinaryName() { return L"Oblivion.exe"; }
virtual GameInfo::Type getType() { return TYPE_OBLIVION; }
@@ -72,9 +72,9 @@ public:
virtual std::wstring getNexusPage(bool nmmScheme = true);
static std::wstring getNexusInfoUrlStatic();
- virtual std::wstring getNexusInfoUrl() { return OblivionInfo::getNexusInfoUrlStatic(); }
+ virtual std::wstring getNexusInfoUrl() { return getNexusInfoUrlStatic(); }
static int getNexusModIDStatic();
- virtual int getNexusModID() { return OblivionInfo::getNexusModIDStatic(); }
+ virtual int getNexusModID() { return getNexusModIDStatic(); }
virtual int getNexusGameID() { return 101; }
virtual void createProfile(const std::wstring &directory, bool useDefaults);
@@ -84,7 +84,7 @@ public:
// get a list of executables (game binary and known-to-work 3rd party tools). All of these are relative to
// the game directory
- virtual std::vector<ExecutableInfo> getExecutables();
+ //virtual std::vector<ExecutableInfo> getExecutables();
virtual std::wstring archiveListKey() { return L"SArchiveList"; }
diff --git a/src/shared/shared.pro b/src/shared/shared.pro
index 84a9c274..69f6f2e6 100644
--- a/src/shared/shared.pro
+++ b/src/shared/shared.pro
@@ -11,33 +11,11 @@ TARGET = mo_shared
TEMPLATE = lib
CONFIG += staticlib
-INCLUDEPATH += ../bsatk "$(BOOSTPATH)"
-
-# only for custom leak detection
-DEFINES += TRACE_LEAKS
-LIBS += -lDbgHelp
-
-
-CONFIG(debug, debug|release) {
- LIBS += -L$$OUT_PWD/../bsatk/debug
- LIBS += -lDbgHelp
- QMAKE_CXXFLAGS_DEBUG -= -Zi
- QMAKE_CXXFLAGS += -Z7
- PRE_TARGETDEPS += $$OUT_PWD/../bsatk/debug/bsatk.lib
-} else {
- LIBS += -L$$OUT_PWD/../bsatk/release
- PRE_TARGETDEPS += $$OUT_PWD/../bsatk/release/bsatk.lib
+!include(../LocalPaths.pri) {
+ message("paths to required libraries need to be set up in LocalPaths.pri")
}
-LIBS += -lbsatk
-
-DEFINES += UNICODE _UNICODE _CRT_SECURE_NO_WARNINGS
-
-DEFINES += BOOST_DISABLE_ASSERTS NDEBUG
-
-# QMAKE_CXXFLAGS += /analyze
-
SOURCES += \
inject.cpp \
windows_error.cpp \
@@ -66,3 +44,30 @@ HEADERS += \
appconfig.h \
appconfig.inc \
leaktrace.h
+
+
+# only for custom leak detection
+DEFINES += TRACE_LEAKS
+LIBS += -lDbgHelp
+
+
+CONFIG(debug, debug|release) {
+ LIBS += -L$$OUT_PWD/../bsatk/debug
+ LIBS += -lDbgHelp
+ QMAKE_CXXFLAGS_DEBUG -= -Zi
+ QMAKE_CXXFLAGS += -Z7
+ PRE_TARGETDEPS += $$OUT_PWD/../bsatk/debug/bsatk.lib
+} else {
+ LIBS += -L$$OUT_PWD/../bsatk/release
+ PRE_TARGETDEPS += $$OUT_PWD/../bsatk/release/bsatk.lib
+}
+
+LIBS += -lbsatk
+
+DEFINES += UNICODE _UNICODE _CRT_SECURE_NO_WARNINGS
+
+DEFINES += BOOST_DISABLE_ASSERTS NDEBUG
+
+# QMAKE_CXXFLAGS += /analyze
+
+INCLUDEPATH += ../bsatk "$${BOOSTPATH}"
diff --git a/src/shared/skyriminfo.cpp b/src/shared/skyriminfo.cpp
index c985fe9f..1203e3ed 100644
--- a/src/shared/skyriminfo.cpp
+++ b/src/shared/skyriminfo.cpp
@@ -63,15 +63,17 @@ std::wstring SkyrimInfo::getRegPathStatic()
0, KEY_QUERY_VALUE, &key);
if (errorcode != ERROR_SUCCESS) {
- return L"";
+ return std::wstring();
}
WCHAR temp[MAX_PATH];
DWORD bufferSize = MAX_PATH;
- errorcode = ::RegQueryValueExW(key, L"Installed Path", NULL, NULL, (LPBYTE)temp, &bufferSize);
-
- return std::wstring(temp);
+ if (::RegQueryValueExW(key, L"Installed Path", NULL, NULL, (LPBYTE)temp, &bufferSize) == ERROR_SUCCESS) {
+ return std::wstring(temp);
+ } else {
+ return std::wstring();
+ }
}
@@ -222,7 +224,7 @@ int SkyrimInfo::getNexusModIDStatic()
void SkyrimInfo::createProfile(const std::wstring &directory, bool useDefaults)
{
{ // copy plugins.txt
- std::wstring target = directory.substr().append(L"\\plugins.txt");
+ std::wstring target = directory + L"\\plugins.txt";
if (!FileExists(target)) {
std::wostringstream source;
source << getLocalAppFolder() << "\\Skyrim\\plugins.txt";
@@ -231,11 +233,10 @@ void SkyrimInfo::createProfile(const std::wstring &directory, bool useDefaults)
::CloseHandle(file);
}
}
- target = directory.substr().append(L"\\loadorder.txt");
+ target = directory + L"\\loadorder.txt";
if (!FileExists(target)) {
- std::wostringstream source;
- source << getLocalAppFolder() << "\\Skyrim\\loadorder.txt";
- if (!::CopyFileW(source.str().c_str(), target.c_str(), true)) {
+ std::wstring source = getLocalAppFolder() + L"\\Skyrim\\loadorder.txt";
+ if (!::CopyFileW(source.c_str(), target.c_str(), true)) {
HANDLE file = ::CreateFileW(target.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
::CloseHandle(file);
}
@@ -243,42 +244,36 @@ void SkyrimInfo::createProfile(const std::wstring &directory, bool useDefaults)
}
{ // copy skyrim.ini-file
- std::wstring target = directory.substr().append(L"\\skyrim.ini");
+ std::wstring target = directory + L"\\skyrim.ini";
if (!FileExists(target)) {
- std::wostringstream source;
+ std::wstring source;
if (useDefaults) {
- source << getGameDirectory() << L"\\skyrim_default.ini";
+ source = getGameDirectory() + L"\\skyrim_default.ini";
} else {
- source << getMyGamesDirectory() << L"\\Skyrim";
- if (FileExists(source.str(), L"skyrim.ini")) {
- source << L"\\skyrim.ini";
+ source = getMyGamesDirectory() + L"\\Skyrim";
+ if (FileExists(source, L"skyrim.ini")) {
+ source += L"\\skyrim.ini";
} else {
- source.str(L"");
- source << getGameDirectory() << L"\\skyrim_default.ini";
+ source = getGameDirectory() + L"\\skyrim_default.ini";
}
}
- if (!::CopyFileW(source.str().c_str(), target.c_str(), true)) {
+ if (!::CopyFileW(source.c_str(), target.c_str(), true)) {
if (::GetLastError() != ERROR_FILE_EXISTS) {
- std::ostringstream stream;
- stream << "failed to copy ini file: " << ToString(source.str(), false);
- throw windows_error(stream.str());
+ throw windows_error(std::string("failed to copy ini file: ") + ToString(source, false));
}
}
}
}
{ // copy skyrimprefs.ini-file
- std::wstring target = directory.substr().append(L"\\skyrimprefs.ini");
+ std::wstring target = directory + L"\\skyrimprefs.ini";
if (!FileExists(target)) {
- std::wostringstream source;
- source << getMyGamesDirectory() << L"\\Skyrim\\skyrimprefs.ini";
- if (!::CopyFileW(source.str().c_str(), target.c_str(), true)) {
- log("failed to copy ini file %ls", source.str().c_str());
+ std::wstring source = getMyGamesDirectory() + L"\\Skyrim\\skyrimprefs.ini";
+ if (!::CopyFileW(source.c_str(), target.c_str(), true)) {
+ log("failed to copy ini file %ls", source.c_str());
// create empty
if (::CreateFileW(target.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL) == INVALID_HANDLE_VALUE) {
- std::ostringstream stream;
- stream << "failed to copy ini file: " << ToString(source.str(), false);
- throw windows_error(stream.str());
+ throw windows_error(std::string("failed to copy ini file: ") + ToString(source, false));
}
}
}
@@ -311,7 +306,7 @@ bool SkyrimInfo::rerouteToProfile(const wchar_t *fileName, const wchar_t *fullPa
}
-std::vector<ExecutableInfo> SkyrimInfo::getExecutables()
+/*std::vector<ExecutableInfo> SkyrimInfo::getExecutables()
{
std::vector<ExecutableInfo> result;
result.push_back(ExecutableInfo(L"SKSE", L"skse_loader.exe", L"", L"", DEFAULT_CLOSE));
@@ -322,6 +317,6 @@ std::vector<ExecutableInfo> SkyrimInfo::getExecutables()
result.push_back(ExecutableInfo(L"Creation Kit", L"CreationKit.exe", L"", L"", DEFAULT_STAY, L"202480"));
return result;
-}
+}*/
} // namespace MOShared
diff --git a/src/shared/skyriminfo.h b/src/shared/skyriminfo.h
index 132f2aee..ad6ab95d 100644
--- a/src/shared/skyriminfo.h
+++ b/src/shared/skyriminfo.h
@@ -38,7 +38,7 @@ public:
virtual unsigned long getBSAVersion();
static std::wstring getRegPathStatic();
- virtual std::wstring getRegPath() { return SkyrimInfo::getRegPathStatic(); }
+ virtual std::wstring getRegPath() { return getRegPathStatic(); }
virtual std::wstring getBinaryName() { return L"TESV.exe"; }
virtual GameInfo::Type getType() { return TYPE_SKYRIM; }
@@ -81,11 +81,11 @@ public:
virtual std::wstring getNexusPage(bool nmmScheme = true);
static std::wstring getNexusInfoUrlStatic();
- virtual std::wstring getNexusInfoUrl() { return SkyrimInfo::getNexusInfoUrlStatic(); }
+ virtual std::wstring getNexusInfoUrl() { return getNexusInfoUrlStatic(); }
static int getNexusModIDStatic();
- virtual int getNexusModID() { return SkyrimInfo::getNexusModIDStatic(); }
+ virtual int getNexusModID() { return getNexusModIDStatic(); }
static int getNexusGameIDStatic() { return 110; }
- virtual int getNexusGameID() { return SkyrimInfo::getNexusGameIDStatic(); }
+ virtual int getNexusGameID() { return getNexusGameIDStatic(); }
virtual void createProfile(const std::wstring &directory, bool useDefaults);
virtual void repairProfile(const std::wstring &directory);
@@ -94,7 +94,7 @@ public:
// get a list of executables (game binary and known-to-work 3rd party tools). All of these are relative to
// the game directory
- virtual std::vector<ExecutableInfo> getExecutables();
+ //virtual std::vector<ExecutableInfo> getExecutables();
virtual std::wstring archiveListKey() { return L"SResourceArchiveList"; }
diff --git a/src/shared/util.cpp b/src/shared/util.cpp
index 61ca9cdc..d4a77929 100644
--- a/src/shared/util.cpp
+++ b/src/shared/util.cpp
@@ -25,6 +25,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <algorithm>
#include <DbgHelp.h>
#include <set>
+#include <boost/scoped_array.hpp>
namespace MOShared {
@@ -64,24 +65,30 @@ bool FileExists(const std::wstring &searchPath, const std::wstring &filename)
std::string ToString(const std::wstring &source, bool utf8)
{
- char buffer[MAX_PATH];
- if (utf8) {
- ::WideCharToMultiByte(CP_UTF8, 0, source.c_str(), -1, buffer, MAX_PATH, NULL, NULL);
- } else {
- ::WideCharToMultiByte(GetACP(), 0, source.c_str(), -1, buffer, MAX_PATH, NULL, NULL);
+ std::string result;
+ UINT codepage = utf8 ? CP_UTF8 : GetACP();
+ int sizeRequired = ::WideCharToMultiByte(codepage, 0, &source[0], -1, NULL, 0, NULL, NULL);
+ if (sizeRequired == 0) {
+ throw windows_error("failed to convert string to multibyte");
}
- return std::string(buffer);
+ // the size returned by WideCharToMultiByte contains zero termination IF -1 is specified for the length.
+ // we don't want that \0 in the string because then the length field would be wrong. Because madness
+ result.resize(sizeRequired - 1, '\0');
+ ::WideCharToMultiByte(codepage, 0, &source[0], (int)source.size(), &result[0], sizeRequired, NULL, NULL);
+ return result;
}
std::wstring ToWString(const std::string &source, bool utf8)
{
- wchar_t buffer[MAX_PATH];
- if (utf8) {
- ::MultiByteToWideChar(CP_UTF8, 0, source.c_str(), -1, buffer, MAX_PATH);
- } else {
- ::MultiByteToWideChar(GetACP(), 0, source.c_str(), -1, buffer, MAX_PATH);
+ std::wstring result;
+ UINT codepage = utf8 ? CP_UTF8 : GetACP();
+ int sizeRequired = ::MultiByteToWideChar(codepage, 0, &source[0], (int)source.size(), NULL, 0);
+ if (sizeRequired == 0) {
+ throw windows_error("failed to convert string to wide character");
}
- return std::wstring(buffer);
+ result.resize(sizeRequired, L'\0');
+ ::MultiByteToWideChar(codepage, 0, &source[0], (int)source.size(), &result[0], sizeRequired);
+ return result;
}
std::string &ToLower(std::string &text)
@@ -112,14 +119,15 @@ std::wstring ToLower(const std::wstring &text)
VS_FIXEDFILEINFO GetFileVersion(const std::wstring &fileName)
{
- DWORD size = ::GetFileVersionInfoSizeW(fileName.c_str(), NULL);
+ DWORD handle;
+ DWORD size = ::GetFileVersionInfoSizeW(fileName.c_str(), &handle);
if (size == 0) {
throw windows_error("failed to determine file version info size");
}
void *buffer = new char[size];
try {
- if (!::GetFileVersionInfoW(fileName.c_str(), 0UL, size, buffer)) {
+ if (!::GetFileVersionInfoW(fileName.c_str(), handle, size, buffer)) {
throw windows_error("failed to determine file version info");
}