forked from deskflow/deskflow
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ansi codepage for multibyte strings (fixes #976)
- Loading branch information
Showing
4 changed files
with
100 additions
and
32 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
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,61 @@ | ||
/* | ||
* barrier -- mouse and keyboard sharing utility | ||
* Copyright (C) 2018 Debauchee Open Source Group | ||
* | ||
* This package is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* found in the file LICENSE that should have accompanied this file. | ||
* | ||
* This package is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "KnownFolderPaths.h" | ||
#include <string> | ||
|
||
#define WIN32_LEAN_AND_MEAN | ||
#include <Windows.h> | ||
#include <Shlobj.h> | ||
|
||
std::string unicode_to_mb(const WCHAR* utfStr) | ||
{ | ||
int utfLength = lstrlenW(utfStr); | ||
int mbLength = WideCharToMultiByte(CP_ACP, 0, utfStr, utfLength, NULL, 0, NULL, NULL); | ||
std::string mbStr(mbLength, 0); | ||
WideCharToMultiByte(CP_ACP, 0, utfStr, utfLength, &mbStr[0], mbLength, NULL, NULL); | ||
return mbStr; | ||
} | ||
|
||
std::string known_folder_path(const KNOWNFOLDERID& id) | ||
{ | ||
std::string path; | ||
WCHAR* buffer; | ||
HRESULT result = SHGetKnownFolderPath(id, 0, NULL, &buffer); | ||
if (result == S_OK) { | ||
path = unicode_to_mb(buffer); | ||
CoTaskMemFree(buffer); | ||
} | ||
return path; | ||
} | ||
|
||
std::string KnownFolderPaths::desktop() | ||
{ | ||
return known_folder_path(FOLDERID_Desktop); | ||
} | ||
|
||
std::string KnownFolderPaths::localAppData() | ||
{ | ||
return known_folder_path(FOLDERID_LocalAppData); | ||
} | ||
|
||
std::string KnownFolderPaths::programData() | ||
{ | ||
return known_folder_path(FOLDERID_ProgramData); | ||
} |
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,32 @@ | ||
/* | ||
* barrier -- mouse and keyboard sharing utility | ||
* Copyright (C) 2018 Debauchee Open Source Group | ||
* | ||
* This package is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* found in the file LICENSE that should have accompanied this file. | ||
* | ||
* This package is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
class KnownFolderPaths | ||
{ | ||
public: | ||
static std::string desktop(); | ||
static std::string localAppData(); | ||
static std::string programData(); | ||
|
||
private: | ||
// static class | ||
KnownFolderPaths() {} | ||
}; |
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