forked from debauchee/barrier
-
Notifications
You must be signed in to change notification settings - Fork 0
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 internal multibyte strings on windows (fixes de…
…bauchee#976, fixes debauchee#974, fixes debauchee#444)
- Loading branch information
Showing
13 changed files
with
151 additions
and
79 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
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
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
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
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,63 @@ | ||
/* | ||
* 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/>. | ||
*/ | ||
|
||
#include "KnownFolderPaths.h" | ||
|
||
#define WIN32_LEAN_AND_MEAN | ||
#include <Windows.h> | ||
#include <Shlobj.h> | ||
|
||
static std::string wide_to_mb(const wchar_t* source, int length) | ||
{ | ||
int ansiLength = WideCharToMultiByte(CP_ACP, 0, source, length, NULL, 0, NULL, NULL); | ||
if (ansiLength > 0) { | ||
std::string ansiString(ansiLength, 0); | ||
ansiLength = WideCharToMultiByte(CP_ACP, 0, source, length, &ansiString[0], ansiLength, NULL, NULL); | ||
if (ansiLength > 0) { | ||
return ansiString; | ||
} | ||
} | ||
return {}; | ||
} | ||
|
||
static std::string known_folder_path(const KNOWNFOLDERID& id) | ||
{ | ||
std::string path; | ||
WCHAR* buffer; | ||
HRESULT result = SHGetKnownFolderPath(id, 0, NULL, &buffer); | ||
if (result == S_OK) { | ||
auto length = lstrlenW(buffer); | ||
path = wide_to_mb(buffer, length); | ||
CoTaskMemFree(buffer); | ||
} | ||
return path; | ||
} | ||
|
||
std::string desktopPath() | ||
{ | ||
return known_folder_path(FOLDERID_Desktop); | ||
} | ||
|
||
std::string localAppDataPath() | ||
{ | ||
return known_folder_path(FOLDERID_LocalAppData); | ||
} | ||
|
||
std::string programDataPath() | ||
{ | ||
return known_folder_path(FOLDERID_ProgramData); | ||
} |
Oops, something went wrong.