Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Path detection based on the registry
Put char conversion methods into a separate file Wrapped language.dll editing in try-catch as it seems to fail sometimes (not sure why) Fixed an eternal loop if copying hotkeys from HD Added some extra checks to the interface slp copying, as this can cause issues if the program is aborted early.
- Loading branch information
Jonas Schmiddunser
committed
Apr 1, 2017
1 parent
22069bb
commit dc6d899
Showing
4 changed files
with
318 additions
and
146 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include <iostream> | ||
#include <set> | ||
#include <map> | ||
#include <algorithm> | ||
#include <cctype> | ||
#include <string> | ||
#include <sstream> | ||
#include <vector> | ||
#include <iterator> | ||
#include <windows.h> | ||
|
||
DWORD ConvertUnicode2CP(const wchar_t *szText, std::string &resultString, UINT codePage) | ||
{ | ||
resultString.clear(); | ||
if (wcslen(szText) <= 0) | ||
return ERROR_SUCCESS; | ||
int iRes = WideCharToMultiByte(codePage, 0, szText, -1, NULL, 0, NULL, NULL); | ||
if (iRes <= 0) | ||
return GetLastError(); | ||
char *szTemp = new char[iRes]; | ||
|
||
iRes = WideCharToMultiByte(codePage, 0, szText, -1, szTemp, iRes, NULL, NULL); | ||
if (iRes <= 0) | ||
{ | ||
delete [] szTemp; | ||
return GetLastError(); | ||
} | ||
|
||
resultString = szTemp; | ||
delete [] szTemp; | ||
return ERROR_SUCCESS; | ||
} | ||
|
||
DWORD ConvertCP2Unicode(const char *szText, std::wstring &resultString, UINT codePage) | ||
{ | ||
resultString.clear(); | ||
if (strlen(szText) <= 0) | ||
return ERROR_SUCCESS; | ||
int iRes = MultiByteToWideChar(codePage, 0, szText, -1, NULL, 0); | ||
if (iRes <= 0) | ||
return GetLastError(); | ||
wchar_t *szTemp = new wchar_t[iRes]; | ||
|
||
iRes = MultiByteToWideChar(codePage, 0, szText, -1, szTemp, iRes); | ||
if (iRes <= 0) | ||
{ | ||
delete [] szTemp; | ||
return GetLastError(); | ||
} | ||
|
||
resultString = szTemp; | ||
delete [] szTemp; | ||
return ERROR_SUCCESS; | ||
} | ||
|
||
std::wstring strtowstr( const std::string& as ) | ||
{ | ||
// deal with trivial case of empty string | ||
if( as.empty() ) return std::wstring(); | ||
|
||
// determine required length of new string | ||
size_t reqLength = ::MultiByteToWideChar( CP_UTF8, 0, as.c_str(), (int)as.length(), 0, 0 ); | ||
|
||
// construct new string of required length | ||
std::wstring ret( reqLength, L'\0' ); | ||
|
||
// convert old string to new string | ||
::MultiByteToWideChar( CP_UTF8, 0, as.c_str(), (int)as.length(), &ret[0], (int)ret.length() ); | ||
|
||
// return new string ( compiler should optimize this away ) | ||
return ret; | ||
} | ||
|
||
std::string wstrtostr( const std::wstring& as ) | ||
{ | ||
// deal with trivial case of empty string | ||
if( as.empty() ) return std::string(); | ||
|
||
// determine required length of new string | ||
size_t reqLength = ::WideCharToMultiByte( CP_UTF8, 0, as.c_str(), (int)as.length(), 0, 0, 0, 0 ); | ||
|
||
// construct new string of required length | ||
std::string ret( reqLength, L'\0' ); | ||
|
||
// convert old string to new string | ||
::WideCharToMultiByte( CP_UTF8, 0, as.c_str(), (int)as.length(), &ret[0], (int)ret.length(), 0, 0 ); | ||
|
||
// return new string ( compiler should optimize this away ) | ||
return ret; | ||
} | ||
|
||
std::vector<std::string> split(const std::string &s, char delim) { | ||
std::vector<std::string> elems; | ||
std::stringstream ss; | ||
ss.str(s); | ||
std::string item; | ||
std::back_insert_iterator<std::vector<std::string>> result = std::back_inserter(elems); | ||
while (std::getline(ss, item, delim)) { | ||
*(result++) = item; | ||
} | ||
return elems; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef CONVERSIONS_H | ||
#define CONVERSIONS_H | ||
|
||
DWORD ConvertUnicode2CP(const wchar_t *szText, std::string &resultString, UINT codePage = CP_ACP); | ||
DWORD ConvertCP2Unicode(const char *szText, std::wstring &resultString, UINT codePage = CP_ACP); | ||
std::wstring strtowstr( const std::string& as ); | ||
std::string wstrtostr( const std::wstring& as ); | ||
std::vector<std::string> split(const std::string &s, char delim); | ||
|
||
#endif // CONVERSIONS_H |
Oops, something went wrong.