|
From: Tapio V. <aa...@us...> - 2010-08-04 15:01:08
|
Module: performous
Branch: portaudio
Commit: 330f88915c5362c8a05ecda3a5d35bec06bdaf4b
Author: Tapio Vierros <tap...@gm...>
Date: Tue Jul 27 22:24:20 2010 +0300
Make sure paths are unique.
---
game/fs.cc | 54 +++++++++++++++++++++++++++++-------------------------
1 files changed, 29 insertions(+), 25 deletions(-)
diff --git a/game/fs.cc b/game/fs.cc
index 79895c2..e56f471 100644
--- a/game/fs.cc
+++ b/game/fs.cc
@@ -6,6 +6,7 @@
#include <cstdlib>
#include <iostream>
#include <sstream>
+#include <algorithm>
#ifdef _WIN32
#include <windows.h>
@@ -40,31 +41,31 @@ fs::path getConfigDir() {
static bool initialized = false;
if (!initialized) {
initialized = true;
- #ifndef _WIN32
- {
- char const* conf = getenv("XDG_CONFIG_HOME");
- if (conf) dir = fs::path(conf) / "performous";
- else dir = getHomeDir() / ".config" / "performous";
- }
- #else
- {
- //open AppData directory
- std::string str;
- ITEMIDLIST* pidl;
- char AppDir[MAX_PATH];
- HRESULT hRes = SHGetSpecialFolderLocation( NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE , &pidl );
- if (hRes==NOERROR)
- {
- SHGetPathFromIDList( pidl, AppDir );
- int i;
- for(i = 0; AppDir[i] != '\0'; i++){
- if(AppDir[i] == '\\') str += '/';
- else str += AppDir[i];
- }
- dir = fs::path(str) / "performous";
- }
- }
- #endif
+ #ifndef _WIN32
+ {
+ char const* conf = getenv("XDG_CONFIG_HOME");
+ if (conf) dir = fs::path(conf) / "performous";
+ else dir = getHomeDir() / ".config" / "performous";
+ }
+ #else
+ {
+ //open AppData directory
+ std::string str;
+ ITEMIDLIST* pidl;
+ char AppDir[MAX_PATH];
+ HRESULT hRes = SHGetSpecialFolderLocation( NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE , &pidl );
+ if (hRes==NOERROR)
+ {
+ SHGetPathFromIDList( pidl, AppDir );
+ int i;
+ for(i = 0; AppDir[i] != '\0'; i++){
+ if(AppDir[i] == '\\') str += '/';
+ else str += AppDir[i];
+ }
+ dir = fs::path(str) / "performous";
+ }
+ }
+ #endif
}
return dir;
}
@@ -174,6 +175,9 @@ Paths const& getPaths(bool refresh) {
// Check if they actually exist and print debug
paths.clear();
std::remove_copy_if(dirs.begin(), dirs.end(), std::inserter(paths, paths.end()), pathNotExist);
+ // Assure that each path appears only once
+ Paths::iterator it = std::unique(paths.begin(), paths.end());
+ paths.resize(it - paths.begin());
}
return paths;
}
|