aboutsummaryrefslogtreecommitdiffstats
path: root/vncviewer/parameters.cxx
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2024-09-06 16:29:25 +0200
committerPierre Ossman <ossman@cendio.se>2024-09-06 16:29:25 +0200
commita19219e0ebeed5701fa8e0bee41d2529ffb7d966 (patch)
treef043ed997c225c37bf905cfc6db52889b730c61e /vncviewer/parameters.cxx
parent4236d0c644a7454ab7a955e837143a8fd0777c09 (diff)
downloadtigervnc-a19219e0ebeed5701fa8e0bee41d2529ffb7d966.tar.gz
tigervnc-a19219e0ebeed5701fa8e0bee41d2529ffb7d966.zip
Use std::list for server history
We don't need random access to the entries, so a list fits just as well. It also has better accessors we need.
Diffstat (limited to 'vncviewer/parameters.cxx')
-rw-r--r--vncviewer/parameters.cxx15
1 files changed, 10 insertions, 5 deletions
diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx
index e40391a2..4bbf7a7f 100644
--- a/vncviewer/parameters.cxx
+++ b/vncviewer/parameters.cxx
@@ -418,7 +418,7 @@ static void removeValue(const char* _name, HKEY* hKey) {
}
}
-void saveHistoryToRegKey(const vector<string>& serverHistory) {
+void saveHistoryToRegKey(const list<string>& serverHistory) {
HKEY hKey;
LONG res = RegCreateKeyExW(HKEY_CURRENT_USER,
L"Software\\TigerVNC\\vncviewer\\history", 0, nullptr,
@@ -433,9 +433,11 @@ void saveHistoryToRegKey(const vector<string>& serverHistory) {
char indexString[3];
try {
- while(index < serverHistory.size() && index <= SERVER_HISTORY_SIZE) {
+ for (const string& entry : serverHistory) {
+ if (index > SERVER_HISTORY_SIZE)
+ break;
snprintf(indexString, 3, "%d", index);
- setKeyString(indexString, serverHistory[index].c_str(), &hKey);
+ setKeyString(indexString, entry.c_str(), &hKey);
index++;
}
} catch (Exception& e) {
@@ -503,8 +505,9 @@ static void saveToReg(const char* servername) {
throw rdr::SystemException(_("Failed to close registry key"), res);
}
-void loadHistoryFromRegKey(vector<string>& serverHistory) {
+list<string> loadHistoryFromRegKey() {
HKEY hKey;
+ list<string> serverHistory;
LONG res = RegOpenKeyExW(HKEY_CURRENT_USER,
L"Software\\TigerVNC\\vncviewer\\history", 0,
@@ -512,7 +515,7 @@ void loadHistoryFromRegKey(vector<string>& serverHistory) {
if (res != ERROR_SUCCESS) {
if (res == ERROR_FILE_NOT_FOUND) {
// The key does not exist, defaults will be used.
- return;
+ return serverHistory;
}
throw rdr::SystemException(_("Failed to open registry key"), res);
@@ -543,6 +546,8 @@ void loadHistoryFromRegKey(vector<string>& serverHistory) {
res = RegCloseKey(hKey);
if (res != ERROR_SUCCESS)
throw rdr::SystemException(_("Failed to close registry key"), res);
+
+ return serverHistory;
}
static void getParametersFromReg(VoidParameter* parameters[],