aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Library/ml_webdev/config.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Src/Plugins/Library/ml_webdev/config.cpp')
-rw-r--r--Src/Plugins/Library/ml_webdev/config.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/Src/Plugins/Library/ml_webdev/config.cpp b/Src/Plugins/Library/ml_webdev/config.cpp
new file mode 100644
index 00000000..6a81bb6c
--- /dev/null
+++ b/Src/Plugins/Library/ml_webdev/config.cpp
@@ -0,0 +1,74 @@
+#include "main.h"
+#include "./config.h"
+#include "./wasabi.h"
+
+#include <shlwapi.h>
+#include <strsafe.h>
+
+#define CONFIG_SUFFIX L"Plugins\\webDev"
+
+static LPCSTR Config_GetPath()
+{
+ static LPSTR configPath = NULL;
+ if (NULL == configPath)
+ {
+ LPCWSTR p = (NULL != WASABI_API_APP) ? WASABI_API_APP->path_getUserSettingsPath() : NULL;
+ if (NULL != p)
+ {
+ WCHAR szBuffer[MAX_PATH * 2] = {0};
+ if (0 != PathCombine(szBuffer, p, CONFIG_SUFFIX))
+ {
+ OMUTILITY->EnsurePathExist(szBuffer);
+ PathAppend(szBuffer, L"config.ini");
+ configPath = Plugin_WideCharToMultiByte(CP_UTF8, 0, szBuffer, -1, NULL, NULL);
+ }
+ }
+ }
+
+ return configPath;
+}
+
+DWORD Config_ReadStr(LPCSTR lpSectionName, LPCSTR lpKeyName, LPCSTR lpDefault, LPSTR lpReturnedString, DWORD nSize)
+{
+ return GetPrivateProfileStringA(lpSectionName, lpKeyName, lpDefault, lpReturnedString, nSize, Config_GetPath());
+}
+
+UINT Config_ReadInt(LPCSTR lpSectionName, LPCSTR lpKeyName, INT nDefault)
+{
+ return GetPrivateProfileIntA(lpSectionName, lpKeyName, nDefault, Config_GetPath());
+}
+
+HRESULT Config_WriteStr(LPCSTR lpSectionName, LPCSTR lpKeyName, LPCSTR lpString)
+{
+ LPCSTR configPath = Config_GetPath();
+ if (NULL == configPath || '\0' == *configPath)
+ return E_UNEXPECTED;
+
+ if (0 != WritePrivateProfileStringA(lpSectionName, lpKeyName, lpString, configPath))
+ return S_OK;
+
+ DWORD errorCode = GetLastError();
+ return HRESULT_FROM_WIN32(errorCode);
+}
+
+HRESULT Config_WriteInt(LPCSTR lpSectionName, LPCSTR lpKeyName, INT nValue)
+{
+ char szBuffer[32];
+ HRESULT hr = StringCchPrintfA(szBuffer, ARRAYSIZE(szBuffer), "%d", nValue);
+ if (FAILED(hr)) return hr;
+
+ return Config_WriteStr(lpSectionName, lpKeyName, szBuffer);
+}
+
+HRESULT Config_WriteSection(LPCSTR lpSectionName, LPCSTR lpData)
+{
+ LPCSTR configPath = Config_GetPath();
+ if (NULL == configPath || '\0' == *configPath)
+ return E_UNEXPECTED;
+
+ if (0 == WritePrivateProfileSectionA(lpSectionName, lpData, configPath))
+ return S_OK;
+
+ DWORD errorCode = GetLastError();
+ return HRESULT_FROM_WIN32(errorCode);
+} \ No newline at end of file