From f215542bde3c6e970c7a8796e0b28882d97d4ceb Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 10 Oct 2019 10:16:38 -0400 Subject: [PATCH 1/4] added new usvfsParameters to replace old USVFSParameters deprecated everything having to do with USVFSParameters removed delayProcess from the old stuff to preserve ABI --- include/usvfs.h | 27 +++++++---- include/usvfsparameters.h | 21 ++++++++- src/usvfs_dll/hookcontext.cpp | 62 ++++++++++++------------- src/usvfs_dll/hookcontext.h | 36 +++++++-------- src/usvfs_dll/hookmanager.cpp | 2 +- src/usvfs_dll/hookmanager.h | 2 +- src/usvfs_dll/hooks/kernel32.cpp | 2 +- src/usvfs_dll/usvfs.cpp | 76 +++++++++++++++++++++++-------- src/usvfs_helper/inject.cpp | 7 +-- src/usvfs_helper/inject.h | 4 +- src/usvfs_proxy/main.cpp | 2 +- vsbuild/usvfs_dll.vcxproj | 2 + vsbuild/usvfs_dll.vcxproj.filters | 6 +++ 13 files changed, 158 insertions(+), 91 deletions(-) diff --git a/include/usvfs.h b/include/usvfs.h index 40bd9d3c..470c986d 100644 --- a/include/usvfs.h +++ b/include/usvfs.h @@ -80,14 +80,20 @@ DLLEXPORT BOOL WINAPI VirtualLinkDirectoryStatic(LPCWSTR source, LPCWSTR destina * connect to a virtual filesystem as a controller, without hooking the calling process. Please note that * you can only be connected to one vfs, so this will silently disconnect from a previous vfs. */ +[[deprecated("deprecated, use usvfsConnectVFS()")]] DLLEXPORT BOOL WINAPI ConnectVFS(const USVFSParameters *parameters); +DLLEXPORT BOOL WINAPI usvfsConnectVFS(const usvfsParameters* p); + /** * @brief create a new VFS. This is similar to ConnectVFS except it guarantees * the vfs is reset before use. */ +[[deprecated("deprecated, use usvfsCreateVFS()")]] DLLEXPORT BOOL WINAPI CreateVFS(const USVFSParameters *parameters); +DLLEXPORT BOOL WINAPI usvfsCreateVFS(const usvfsParameters* p); + /** * disconnect from a virtual filesystem. This removes hooks if necessary */ @@ -117,11 +123,6 @@ DLLEXPORT BOOL WINAPI CreateProcessHooked( */ DLLEXPORT bool WINAPI GetLogMessages(LPSTR buffer, size_t size, bool blocking = false); -/** - * @brief Used to change parameters which can be changed in runtime - */ -DLLEXPORT void WINAPI USVFSUpdateParams(LogLevel level, CrashDumpsType type); - /** * retrieves a readable representation of the vfs tree * @param buffer the buffer to write to. this may be null if you only want to determine the required @@ -170,14 +171,24 @@ DLLEXPORT void WINAPI InitLogging(bool toLocal = false); */ DLLEXPORT void __cdecl InitHooks(LPVOID userData, size_t userDataSize); - +[[deprecated("deprecated, use usvfsCreateParameters()")]] DLLEXPORT void WINAPI USVFSInitParameters(USVFSParameters *parameters, const char *instanceName, bool debugMode, LogLevel logLevel, CrashDumpsType crashDumpsType, - const char *crashDumpsPath, - std::chrono::milliseconds delayProcess={}); + const char *crashDumpsPath); + +/** +* @brief Used to change parameters which can be changed in runtime +*/ +[[deprecated("deprecated, use usvfsUpdateParameters()")]] +DLLEXPORT void WINAPI USVFSUpdateParams(LogLevel level, CrashDumpsType type); + +// the only information used from the parameters are the crash dump type, log +// level and process delay +// +DLLEXPORT void WINAPI usvfsUpdateParameters(usvfsParameters* p); DLLEXPORT int WINAPI CreateMiniDump(PEXCEPTION_POINTERS exceptionPtrs, CrashDumpsType type, const wchar_t* dumpPath); diff --git a/include/usvfsparameters.h b/include/usvfsparameters.h index 7aaf4d73..f0710b8f 100644 --- a/include/usvfsparameters.h +++ b/include/usvfsparameters.h @@ -31,8 +31,11 @@ enum class CrashDumpsType : uint8_t { Full }; -extern "C" { +extern "C" +{ +// deprecated, use usvfsParameters and usvfsCreateParameters() +// struct USVFSParameters { char instanceName[65]; char currentSHMName[65]; @@ -41,7 +44,21 @@ struct USVFSParameters { LogLevel logLevel{LogLevel::Debug}; CrashDumpsType crashDumpsType{CrashDumpsType::None}; char crashDumpsPath[260]; - std::chrono::milliseconds delayProcess{0}; }; + +struct usvfsParameters; + +DLLEXPORT usvfsParameters* usvfsCreateParameters(); +DLLEXPORT usvfsParameters* usvfsDupeParameters(usvfsParameters* p); +DLLEXPORT void usvfsCopyParameters(const usvfsParameters* source, usvfsParameters* dest); +DLLEXPORT void usvfsFreeParameters(usvfsParameters* p); + +DLLEXPORT void usvfsSetInstanceName(usvfsParameters* p, const char* name); +DLLEXPORT void usvfsSetDebugMode(usvfsParameters* p, BOOL debugMode); +DLLEXPORT void usvfsSetLogLevel(usvfsParameters* p, LogLevel level); +DLLEXPORT void usvfsSetCrashDumpType(usvfsParameters* p, CrashDumpsType type); +DLLEXPORT void usvfsSetCrashDumpPath(usvfsParameters* p, const char* path); +DLLEXPORT void usvfsSetProcessDelay(usvfsParameters* p, int milliseconds); + } diff --git a/src/usvfs_dll/hookcontext.cpp b/src/usvfs_dll/hookcontext.cpp index b0a13049..72965a32 100644 --- a/src/usvfs_dll/hookcontext.cpp +++ b/src/usvfs_dll/hookcontext.cpp @@ -56,41 +56,19 @@ void printBuffer(const char *buffer, size_t size) } -USVFSParameters SharedParameters::makeLocal() const +usvfsParameters SharedParameters::makeLocal() const { - USVFSParameters result; - USVFSInitParametersInt(&result, instanceName.c_str(), - currentSHMName.c_str(), - currentInverseSHMName.c_str(), - debugMode, logLevel, crashDumpsType, - crashDumpsPath.c_str(), - delayProcess); - return result; -} - - -void usvfs::USVFSInitParametersInt(USVFSParameters *parameters, - const char *instanceName, - const char *currentSHMName, - const char *currentInverseSHMName, - bool debugMode, - LogLevel logLevel, - CrashDumpsType crashDumpsType, - const char *crashDumpsPath, - std::chrono::milliseconds delayProcess) -{ - parameters->debugMode = debugMode; - parameters->logLevel = logLevel; - parameters->crashDumpsType = crashDumpsType; - parameters->delayProcess = delayProcess; - strncpy_s(parameters->instanceName, instanceName, _TRUNCATE); - strncpy_s(parameters->currentSHMName, currentSHMName, _TRUNCATE); - strncpy_s(parameters->currentInverseSHMName, currentInverseSHMName, _TRUNCATE); - strncpy_s(parameters->crashDumpsPath, crashDumpsPath, _TRUNCATE); + return usvfsParameters( + instanceName.c_str(), + currentSHMName.c_str(), + currentInverseSHMName.c_str(), + debugMode, logLevel, crashDumpsType, + crashDumpsPath.c_str(), + delayProcess.count()); } -HookContext::HookContext(const USVFSParameters ¶ms, HMODULE module) +HookContext::HookContext(const usvfsParameters& params, HMODULE module) : m_ConfigurationSHM(bi::open_or_create, params.instanceName, 8192) , m_Parameters(retrieveParameters(params)) , m_Tree(m_Parameters->currentSHMName.c_str(), 65536) @@ -135,7 +113,7 @@ HookContext::~HookContext() } } -SharedParameters *HookContext::retrieveParameters(const USVFSParameters ¶ms) +SharedParameters *HookContext::retrieveParameters(const usvfsParameters& params) { std::pair res = m_ConfigurationSHM.find("parameters"); @@ -182,13 +160,18 @@ void HookContext::setCrashDumpsType(CrashDumpsType type) m_Parameters->crashDumpsType = type; } +void HookContext::setDelayProcess(std::chrono::milliseconds delay) +{ + m_Parameters->delayProcess = delay; +} + void HookContext::updateParameters() const { m_Parameters->currentSHMName = m_Tree.shmName().c_str(); m_Parameters->currentInverseSHMName = m_InverseTree.shmName().c_str(); } -USVFSParameters HookContext::callParameters() const +usvfsParameters HookContext::callParameters() const { updateParameters(); return m_Parameters->makeLocal(); @@ -308,7 +291,18 @@ void HookContext::unlockShared(const HookContext *instance) instance->m_Mutex.signal(); } -extern "C" DLLEXPORT HookContext *__cdecl CreateHookContext(const USVFSParameters ¶ms, HMODULE module) + +// deprecated +// +extern "C" DLLEXPORT HookContext *__cdecl CreateHookContext( + const USVFSParameters &oldParams, HMODULE module) +{ + const usvfsParameters p(oldParams); + return usvfsCreateHookContext(p, module); +} + +extern "C" DLLEXPORT usvfs::HookContext* WINAPI usvfsCreateHookContext( + const usvfsParameters& params, HMODULE module) { return new HookContext(params, module); } diff --git a/src/usvfs_dll/hookcontext.h b/src/usvfs_dll/hookcontext.h index fda4598c..f23c71bc 100644 --- a/src/usvfs_dll/hookcontext.h +++ b/src/usvfs_dll/hookcontext.h @@ -24,6 +24,7 @@ along with usvfs. If not, see . #include "dllimport.h" #include "semaphore.h" #include +#include #include #include #include @@ -42,17 +43,6 @@ along with usvfs. If not, see . namespace usvfs { -void USVFSInitParametersInt(USVFSParameters *parameters, - const char *instanceName, - const char *currentSHMName, - const char *currentInverseSHMName, - bool debugMode, - LogLevel logLevel, - CrashDumpsType crashDumpsType, - const char *crashDumpsPath, - std::chrono::milliseconds delayProcess); - - typedef shared::VoidAllocatorT::rebind::other DWORDAllocatorT; typedef shared::VoidAllocatorT::rebind::other StringAllocatorT; @@ -78,7 +68,7 @@ struct SharedParameters { SharedParameters &operator=(const SharedParameters &reference) = delete; - SharedParameters(const USVFSParameters &reference, + SharedParameters(const usvfsParameters& reference, const shared::VoidAllocatorT &allocator) : instanceName(reference.instanceName, allocator) , currentSHMName(reference.currentSHMName, allocator) @@ -87,7 +77,7 @@ struct SharedParameters { , logLevel(reference.logLevel) , crashDumpsType(reference.crashDumpsType) , crashDumpsPath(reference.crashDumpsPath, allocator) - , delayProcess(reference.delayProcess) + , delayProcess(reference.delayProcessMs) , userCount(1) , processBlacklist(allocator) , processList(allocator) @@ -95,7 +85,7 @@ struct SharedParameters { { } - DLLEXPORT USVFSParameters makeLocal() const; + DLLEXPORT usvfsParameters makeLocal() const; shared::StringT instanceName; shared::StringT currentSHMName; @@ -127,7 +117,7 @@ class HookContext typedef unsigned int DataIDT; public: - HookContext(const USVFSParameters ¶ms, HMODULE module); + HookContext(const usvfsParameters& params, HMODULE module); HookContext(const HookContext &reference) = delete; @@ -180,7 +170,7 @@ class HookContext /** * @return the parameters passed in on dll initialisation */ - USVFSParameters callParameters() const; + usvfsParameters callParameters() const; /** * @return true if usvfs is running in debug mode @@ -228,6 +218,7 @@ class HookContext void setLogLevel(LogLevel level); void setCrashDumpsType(CrashDumpsType type); + void setDelayProcess(std::chrono::milliseconds delay); void updateParameters() const; @@ -239,7 +230,7 @@ class HookContext static void unlock(HookContext *instance); static void unlockShared(const HookContext *instance); - SharedParameters *retrieveParameters(const USVFSParameters ¶ms); + SharedParameters* retrieveParameters(const usvfsParameters& params); private: static HookContext *s_Instance; @@ -261,12 +252,19 @@ class HookContext // mutable std::recursive_mutex m_Mutex; mutable RecursiveBenaphore m_Mutex; }; -} + +} // namespace + // exposed only to unit tests for easier testability -extern "C" DLLEXPORT usvfs::HookContext *__cdecl CreateHookContext( +extern "C" [[deprecated("deprecated, use usvfsCreateHookContext()")]] +DLLEXPORT usvfs::HookContext *__cdecl CreateHookContext( const USVFSParameters ¶ms, HMODULE module); +extern "C" DLLEXPORT usvfs::HookContext* WINAPI usvfsCreateHookContext( + const usvfsParameters& params, HMODULE module); + + class PreserveGetLastError { public: diff --git a/src/usvfs_dll/hookmanager.cpp b/src/usvfs_dll/hookmanager.cpp index 7bb1634b..cfca76a8 100644 --- a/src/usvfs_dll/hookmanager.cpp +++ b/src/usvfs_dll/hookmanager.cpp @@ -46,7 +46,7 @@ namespace usvfs { HookManager *HookManager::s_Instance = nullptr; -HookManager::HookManager(const USVFSParameters ¶ms, HMODULE module) +HookManager::HookManager(const usvfsParameters& params, HMODULE module) : m_Context(params, module) { if (s_Instance != nullptr) { diff --git a/src/usvfs_dll/hookmanager.h b/src/usvfs_dll/hookmanager.h index 68c1e557..bc0a65fb 100644 --- a/src/usvfs_dll/hookmanager.h +++ b/src/usvfs_dll/hookmanager.h @@ -32,7 +32,7 @@ class HookManager { public: - HookManager(const USVFSParameters ¶ms, HMODULE module); + HookManager(const usvfsParameters& params, HMODULE module); ~HookManager(); HookManager(const HookManager &reference) = delete; diff --git a/src/usvfs_dll/hooks/kernel32.cpp b/src/usvfs_dll/hooks/kernel32.cpp index 2f4a7d2a..3e788369 100644 --- a/src/usvfs_dll/hooks/kernel32.cpp +++ b/src/usvfs_dll/hooks/kernel32.cpp @@ -226,7 +226,7 @@ BOOL WINAPI usvfs::hook_CreateProcessInternalW( LPWSTR cend = nullptr; std::wstring dllPath; - USVFSParameters callParameters; + usvfsParameters callParameters; { // scope for context lock auto context = READ_CONTEXT(); diff --git a/src/usvfs_dll/usvfs.cpp b/src/usvfs_dll/usvfs.cpp index 39d84db7..31070f33 100644 --- a/src/usvfs_dll/usvfs.cpp +++ b/src/usvfs_dll/usvfs.cpp @@ -21,6 +21,7 @@ along with usvfs. If not, see . #include "usvfs.h" #include "usvfs_version.h" #include "hookmanager.h" +#include "usvfsparametersprivate.h" #include "redirectiontree.h" #include "loghelpers.h" #include @@ -144,7 +145,7 @@ void WINAPI InitLogging(bool toConsole) InitLoggingInternal(toConsole, false); } -extern "C" DLLEXPORT bool WINAPI GetLogMessages(char *buffer, size_t size, +extern "C" DLLEXPORT bool WINAPI GetLogMessages(LPSTR buffer, size_t size, bool blocking) { buffer[0] = '\0'; @@ -168,16 +169,32 @@ void SetLogLevel(LogLevel level) spdlog::get("hooks")->set_level(ConvertLogLevel(level)); } -extern "C" void WINAPI USVFSUpdateParams(LogLevel level, CrashDumpsType type) +// deprecated +// +void WINAPI USVFSUpdateParams(LogLevel level, CrashDumpsType type) +{ + auto* p = usvfsCreateParameters(); + + usvfsSetLogLevel(p, level); + usvfsSetCrashDumpType(p, type); + + usvfsUpdateParameters(p); + usvfsFreeParameters(p); +} + +void WINAPI usvfsUpdateParameters(usvfsParameters* p) { // update actual values used: - usvfs_dump_type = type; - SetLogLevel(level); + usvfs_dump_type = p->crashDumpsType; + SetLogLevel(p->logLevel); + // update parameters in context so spawned process will inherit changes: - context->setLogLevel(level); - context->setCrashDumpsType(type); + context->setLogLevel(p->logLevel); + context->setCrashDumpsType(p->crashDumpsType); + context->setDelayProcess(std::chrono::milliseconds(p->delayProcessMs)); } + // // Structured Exception handling // @@ -265,8 +282,8 @@ int WINAPI CreateMiniDump(PEXCEPTION_POINTERS exceptionPtrs, CrashDumpsType type } static bool exceptionInUSVFS(PEXCEPTION_POINTERS exceptionPtrs) { - if (!dllModule) // shouldn't happend, check just in case - return true; // create dump to better understand how this could happend + if (!dllModule) // shouldn't happen, check just in case + return true; // create dump to better understand how this could happen std::pair range = winapi::ex::getSectionRange(dllModule); @@ -299,7 +316,7 @@ LONG WINAPI VEHandler(PEXCEPTION_POINTERS exceptionPtrs) // inside our hooks at least on x64, which is the main reason why want a crash collection // from usvfs. // As a workaround/compromise we catch vectored exception but only ones that originate - // direactly within the usvfs code: + // directly within the usvfs code: if (!exceptionInUSVFS(exceptionPtrs)) return EXCEPTION_CONTINUE_SEARCH; @@ -323,12 +340,12 @@ void __cdecl InitHooks(LPVOID parameters, size_t) { InitLoggingInternal(false, true); - const USVFSParameters *params = reinterpret_cast(parameters); + const usvfsParameters* params = reinterpret_cast(parameters); usvfs_dump_type = params->crashDumpsType; usvfs_dump_path = ush::string_cast(params->crashDumpsPath, ush::CodePage::UTF8); - if (params->delayProcess.count() > 0) { - ::Sleep(static_cast(params->delayProcess.count())); + if (params->delayProcessMs > 0) { + ::Sleep(static_cast(params->delayProcessMs)); } SetLogLevel(params->logLevel); @@ -384,13 +401,34 @@ void WINAPI GetCurrentVFSName(char *buffer, size_t size) } -BOOL WINAPI CreateVFS(const USVFSParameters *params) +// deprecated +// +BOOL WINAPI CreateVFS(const USVFSParameters *oldParams) +{ + const usvfsParameters p(*oldParams); + const auto r = usvfsCreateVFS(&p); + + return r; +} + +BOOL WINAPI usvfsCreateVFS(const usvfsParameters* p) +{ + usvfs::HookContext::remove(p->instanceName); + return usvfsConnectVFS(p); +} + + +// deprecated +// +BOOL WINAPI ConnectVFS(const USVFSParameters *oldParams) { - usvfs::HookContext::remove(params->instanceName); - return ConnectVFS(params); + const usvfsParameters p(*oldParams); + const auto r = usvfsConnectVFS(&p); + + return r; } -BOOL WINAPI ConnectVFS(const USVFSParameters *params) +BOOL WINAPI usvfsConnectVFS(const usvfsParameters* params) { if (spdlog::get("usvfs").get() == nullptr) { // create temporary logger so we don't get null-pointer exceptions @@ -775,17 +813,17 @@ VOID WINAPI PrintDebugInfo() } +// deprecated +// void WINAPI USVFSInitParameters(USVFSParameters *parameters, const char *instanceName, bool debugMode, LogLevel logLevel, CrashDumpsType crashDumpsType, - const char *crashDumpsPath, - std::chrono::milliseconds delayProcess) + const char *crashDumpsPath) { parameters->debugMode = debugMode; parameters->logLevel = logLevel; parameters->crashDumpsType = crashDumpsType; - parameters->delayProcess = delayProcess; strncpy_s(parameters->instanceName, instanceName, _TRUNCATE); if (crashDumpsPath && *crashDumpsPath && strlen(crashDumpsPath) < _countof(parameters->crashDumpsPath)) { diff --git a/src/usvfs_helper/inject.cpp b/src/usvfs_helper/inject.cpp index 0f275094..7835c4dd 100644 --- a/src/usvfs_helper/inject.cpp +++ b/src/usvfs_helper/inject.cpp @@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License along with usvfs. If not, see . */ #include "inject.h" +#include "usvfsparametersprivate.h" #include #include #include @@ -36,14 +37,14 @@ namespace ush = usvfs::shared; using namespace winapi; void usvfs::injectProcess(const std::wstring &applicationPath - , const USVFSParameters ¶meters + , const usvfsParameters ¶meters , const PROCESS_INFORMATION &processInfo) { injectProcess(applicationPath, parameters, processInfo.hProcess, processInfo.hThread); } void usvfs::injectProcess(const std::wstring &applicationPath - , const USVFSParameters ¶meters + , const usvfsParameters ¶meters , HANDLE processHandle , HANDLE threadHandle) { @@ -106,7 +107,7 @@ void usvfs::injectProcess(const std::wstring &applicationPath spdlog::get("usvfs")->info("dll path: {}", log::wrap(dllPath.wstring())); InjectLib::InjectDLL(processHandle, threadHandle, dllPath.c_str(), - "InitHooks", ¶meters, sizeof(USVFSParameters)); + "InitHooks", ¶meters, sizeof(parameters)); spdlog::get("usvfs")->info("injection to same bitness process {} successful", ::GetProcessId(processHandle)); } else { diff --git a/src/usvfs_helper/inject.h b/src/usvfs_helper/inject.h index 737ef53e..cfec39aa 100644 --- a/src/usvfs_helper/inject.h +++ b/src/usvfs_helper/inject.h @@ -33,7 +33,7 @@ namespace usvfs { * @param processInfo */ void injectProcess(const std::wstring &applicationPath - , const USVFSParameters ¶meters + , const usvfsParameters ¶meters , const PROCESS_INFORMATION &processInfo); /** @@ -45,7 +45,7 @@ void injectProcess(const std::wstring &applicationPath * a new thread is created in the process */ void injectProcess(const std::wstring &applicationPath - , const USVFSParameters ¶meters + , const usvfsParameters ¶meters , HANDLE process, HANDLE thread); } diff --git a/src/usvfs_proxy/main.cpp b/src/usvfs_proxy/main.cpp index c1f4a983..31cd5abd 100644 --- a/src/usvfs_proxy/main.cpp +++ b/src/usvfs_proxy/main.cpp @@ -151,7 +151,7 @@ int main(int argc, char **argv) { return 1; } - USVFSParameters par = params.first->makeLocal(); + usvfsParameters par = params.first->makeLocal(); boost::filesystem::path p(winapi::wide::getModuleFileName(nullptr)); diff --git a/vsbuild/usvfs_dll.vcxproj b/vsbuild/usvfs_dll.vcxproj index 3446d90f..968a9a50 100644 --- a/vsbuild/usvfs_dll.vcxproj +++ b/vsbuild/usvfs_dll.vcxproj @@ -214,12 +214,14 @@ + + diff --git a/vsbuild/usvfs_dll.vcxproj.filters b/vsbuild/usvfs_dll.vcxproj.filters index 407a9c5f..c8033810 100644 --- a/vsbuild/usvfs_dll.vcxproj.filters +++ b/vsbuild/usvfs_dll.vcxproj.filters @@ -56,6 +56,9 @@ Source Files + + Source Files + @@ -106,5 +109,8 @@ Header Files + + Header Files\include + \ No newline at end of file From dc845548488390e13e8deb2f4ade675d1fedf637 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 10 Oct 2019 10:48:33 -0400 Subject: [PATCH 2/4] add Proxy to the file description --- src/usvfs_proxy/version.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usvfs_proxy/version.rc b/src/usvfs_proxy/version.rc index 7897f8cb..e95c58c5 100644 --- a/src/usvfs_proxy/version.rc +++ b/src/usvfs_proxy/version.rc @@ -22,7 +22,7 @@ BEGIN BEGIN VALUE "FileVersion", VER_FILEVERSION_STR VALUE "CompanyName", "Mod Organizer 2 Team\0" - VALUE "FileDescription", "USVFS\0" + VALUE "FileDescription", "USVFS Proxy\0" #ifdef _WIN64 VALUE "OriginalFilename", "usvfs_proxy_x64.exe\0" #else From be8e2e41965e67a0f784b933acff7bb4d0dda54f Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 10 Oct 2019 10:51:17 -0400 Subject: [PATCH 3/4] missing files --- include/usvfsparametersprivate.h | 37 +++++++ src/usvfs_dll/usvfsparameters.cpp | 165 ++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 include/usvfsparametersprivate.h create mode 100644 src/usvfs_dll/usvfsparameters.cpp diff --git a/include/usvfsparametersprivate.h b/include/usvfsparametersprivate.h new file mode 100644 index 00000000..688d1e0f --- /dev/null +++ b/include/usvfsparametersprivate.h @@ -0,0 +1,37 @@ +#pragma once +#include "usvfsparameters.h" + +struct usvfsParameters +{ + char instanceName[65]; + char currentSHMName[65]; + char currentInverseSHMName[65]; + bool debugMode; + LogLevel logLevel{LogLevel::Debug}; + CrashDumpsType crashDumpsType{CrashDumpsType::None}; + char crashDumpsPath[260]; + int delayProcessMs; + + usvfsParameters(); + usvfsParameters(const usvfsParameters&) = default; + usvfsParameters& operator=(const usvfsParameters&) = default; + + usvfsParameters( + const char* instanceName, + const char* currentSHMName, + const char* currentInverseSHMName, + bool debugMode, + LogLevel logLevel, + CrashDumpsType crashDumpsType, + const char* crashDumpsPath, + int delayProcessMs); + + usvfsParameters(const USVFSParameters& oldParams); + + void setInstanceName(const char* name); + void setDebugMode(bool debugMode); + void setLogLevel(LogLevel level); + void setCrashDumpType(CrashDumpsType type); + void setCrashDumpPath(const char* path); + void setProcessDelay(int milliseconds); +}; diff --git a/src/usvfs_dll/usvfsparameters.cpp b/src/usvfs_dll/usvfsparameters.cpp new file mode 100644 index 00000000..60900b4f --- /dev/null +++ b/src/usvfs_dll/usvfsparameters.cpp @@ -0,0 +1,165 @@ +#include "usvfsparametersprivate.h" +#include + +usvfsParameters::usvfsParameters() : + debugMode(false), logLevel(LogLevel::Debug), + crashDumpsType(CrashDumpsType::None), delayProcessMs(0) +{ + std::fill(std::begin(instanceName), std::end(instanceName), 0); + std::fill(std::begin(currentSHMName), std::end(currentSHMName), 0); + std::fill(std::begin(currentInverseSHMName), std::end(currentInverseSHMName), 0); + std::fill(std::begin(crashDumpsPath), std::end(crashDumpsPath), 0); +} + +usvfsParameters::usvfsParameters( + const char *instanceName, + const char *currentSHMName, + const char *currentInverseSHMName, + bool debugMode, + LogLevel logLevel, + CrashDumpsType crashDumpsType, + const char *crashDumpsPath, + int delayProcessMs) + : usvfsParameters() +{ + strncpy_s(this->instanceName, instanceName, _TRUNCATE); + strncpy_s(this->currentSHMName, currentSHMName, _TRUNCATE); + strncpy_s(this->currentInverseSHMName, currentInverseSHMName, _TRUNCATE); + this->debugMode = debugMode; + this->logLevel = logLevel; + this->crashDumpsType = crashDumpsType; + strncpy_s(this->crashDumpsPath, crashDumpsPath, _TRUNCATE); + this->delayProcessMs = delayProcessMs; +} + +usvfsParameters::usvfsParameters(const USVFSParameters& oldParams) : + usvfsParameters( + oldParams.instanceName, + oldParams.currentSHMName, + oldParams.currentInverseSHMName, + oldParams.debugMode, + oldParams.logLevel, + oldParams.crashDumpsType, + oldParams.crashDumpsPath, + 0) +{ +} + +void usvfsParameters::setInstanceName(const char* name) +{ + strncpy_s(instanceName, name, _TRUNCATE); + strncpy_s(currentSHMName, 60, name, _TRUNCATE); + memset(currentInverseSHMName, '\0', _countof(currentInverseSHMName)); + _snprintf(currentInverseSHMName, 60, "inv_%s", name); +} + +void usvfsParameters::setDebugMode(bool b) +{ + debugMode = b; +} + +void usvfsParameters::setLogLevel(LogLevel level) +{ + logLevel = level; +} + +void usvfsParameters::setCrashDumpType(CrashDumpsType type) +{ + crashDumpsType = type; +} + +void usvfsParameters::setCrashDumpPath(const char* path) +{ + if (path && *path && strlen(path) < _countof(crashDumpsPath)) { + memcpy(crashDumpsPath, path, strlen(path)+1); + } else { + // crashDumpsPath invalid or overflow of USVFSParameters variable so disable + // crash dumps: + crashDumpsPath[0] = 0; + crashDumpsType = CrashDumpsType::None; + } +} + +void usvfsParameters::setProcessDelay(int milliseconds) +{ + delayProcessMs = milliseconds; +} + + +extern "C" +{ + +usvfsParameters* usvfsCreateParameters() +{ + return new (std::nothrow) usvfsParameters; +} + +usvfsParameters* usvfsDupeParameters(usvfsParameters* p) +{ + if (!p) { + return nullptr; + } + + auto* dupe = usvfsCreateParameters(); + if (!dupe) { + return nullptr; + } + + *dupe = *p; + + return dupe; +} + +void usvfsCopyParameters(const usvfsParameters* source, usvfsParameters* dest) +{ + *dest = *source; +} + +void usvfsFreeParameters(usvfsParameters* p) +{ + delete p; +} + +void usvfsSetInstanceName(usvfsParameters* p, const char* name) +{ + if (p) { + p->setInstanceName(name); + } +} + +void usvfsSetDebugMode(usvfsParameters* p, BOOL debugMode) +{ + if (p) { + p->setDebugMode(debugMode); + } +} + +void usvfsSetLogLevel(usvfsParameters* p, LogLevel level) +{ + if (p) { + p->setLogLevel(level); + } +} + +void usvfsSetCrashDumpType(usvfsParameters* p, CrashDumpsType type) +{ + if (p) { + p->setCrashDumpType(type); + } +} + +void usvfsSetCrashDumpPath(usvfsParameters* p, const char* path) +{ + if (p) { + p->setCrashDumpPath(path); + } +} + +void usvfsSetProcessDelay(usvfsParameters* p, int milliseconds) +{ + if (p) { + p->setProcessDelay(milliseconds); + } +} + +} // extern "C" From 2d515e7a43b5a0a408a564dfe7b36c8d135efb14 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Fri, 11 Oct 2019 08:17:40 -0400 Subject: [PATCH 4/4] added build log files to ignore list --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 65fc28fe..14ef70b2 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,7 @@ *.vcxproj.user msbuild.log +/stderr.log +/stderr_32.log +/stdout.log +/stdout_32.log