Permalink
Browse files

Fixed issue loading non-ascii user image filenames on windows.

  • Loading branch information...
1 parent c8d37e3 commit 2ba358bc8c4ab4929a5164a88077ea616c9621e5 @acaudwell committed Apr 1, 2013
Showing with 45 additions and 27 deletions.
  1. +1 −0 ChangeLog
  2. +10 −7 src/formats/commitlog.cpp
  3. +1 −2 src/formats/commitlog.h
  4. +33 −18 src/gource_settings.cpp
View
@@ -1,6 +1,7 @@
0.40:
* Added caption support.
* Fixed directory deletion short circuiting processing the rest of a commit.
+ * Fixed issue loading non-ascii user image filenames on windows.
* Fix to boost macros for Macs and non-GNU systems (mistydemeo).
* Autotools improvements (flameeyes).
@@ -19,17 +19,20 @@
#include "../gource_settings.h"
#include "../core/sdlapp.h"
-std::string munge_utf8(const std::string& str) {
+#include "../core/utf8/utf8.h"
+
+std::string filter_utf8(const std::string& str) {
+
+ std::string filtered;
- std::string munged;
try {
- utf8::replace_invalid(str.begin(), str.end(), back_inserter(munged), '?');
+ utf8::replace_invalid(str.begin(), str.end(), back_inserter(filtered), '?');
}
catch(...) {
- munged = "???";
+ filtered = "???";
}
- return munged;
+ return filtered;
}
//RCommitLog
@@ -270,7 +273,7 @@ void RCommitLog::createTempLog() {
RCommitFile::RCommitFile(const std::string& filename, const std::string& action, vec3 colour) {
- this->filename = munge_utf8(filename);
+ this->filename = filter_utf8(filename);
//prepend a root slash
if(this->filename[0] != '/') {
@@ -320,7 +323,7 @@ void RCommit::addFile(const std::string& filename, const std::string& action, c
}
void RCommit::postprocess() {
- username = munge_utf8(username);
+ username = filter_utf8(username);
}
bool RCommit::isValid() {
@@ -23,7 +23,6 @@
#include "../core/display.h"
#include "../core/regex.h"
#include "../core/stringhash.h"
-#include "../core/utf8/utf8.h"
#include <time.h>
#include <string>
@@ -85,7 +84,7 @@ class RCommitLog {
public:
RCommitLog(const std::string& logfile, int firstChar = -1);
virtual ~RCommitLog();
-
+
void seekTo(float percent);
bool checkFormat();
@@ -18,6 +18,11 @@
#include "gource_settings.h"
#include "core/sdlapp.h"
+#include <boost/filesystem.hpp>
+#include <boost/algorithm/string.hpp>
+
+#include "core/utf8/utf8.h"
+
GourceSettings gGourceSettings;
//display help message
@@ -665,26 +670,39 @@ void GourceSettings::importGourceSettings(ConfFile& conffile, ConfSection* gourc
user_image_dir += std::string("/");
}
- //get jpg and png images in dir
- DIR *dp;
- struct dirent *dirp;
-
user_image_map.clear();
- if((dp = opendir(gGourceSettings.user_image_dir.c_str())) != 0) {
+ boost::filesystem::path image_dir_path(user_image_dir);
- while ((dirp = readdir(dp)) != 0) {
- std::string dirfile = std::string(dirp->d_name);
+ if(!is_directory(image_dir_path)) {
+ conffile.entryException(entry, "specified user-image-dir is not a directory");
+ }
- size_t extpos = 0;
+ std::vector<boost::filesystem::path> image_dir_files;
- if( (extpos=dirfile.rfind(".jpg")) == std::string::npos
- && (extpos=dirfile.rfind(".jpeg")) == std::string::npos
- && (extpos=dirfile.rfind(".png")) == std::string::npos) continue;
+ try {
+ copy(boost::filesystem::directory_iterator(image_dir_path), boost::filesystem::directory_iterator(), back_inserter(image_dir_files));
+ } catch(const boost::filesystem::filesystem_error& exception) {
+ conffile.entryException(entry, "error reading specified user-image-dir");
+ }
+ for(boost::filesystem::path& p : image_dir_files) {
- std::string image_path = gGourceSettings.user_image_dir + dirfile;
- std::string name = dirfile.substr(0,extpos);
+ std::string dirfile;
+
+#ifdef _WIN32
+ std::wstring dirfile_16 = p.filename().wstring();
+ utf8::utf16to8(dirfile_16.begin(), dirfile_16.end(), back_inserter(dirfile));
+#else
+ dirfile = p.filename().string();
+#endif
+ std::string file_ext = extension(p);
+ boost::algorithm::to_lower(file_ext);
+
+ if(file_ext != ".jpg" && file_ext != ".jpeg" && file_ext != ".png") continue;
+
+ std::string image_path = gGourceSettings.user_image_dir + dirfile;
+ std::string name = dirfile.substr(0,dirfile.size() - file_ext.size());
#ifdef __APPLE__
CFMutableStringRef help = CFStringCreateMutable(kCFAllocatorDefault, 0);
@@ -698,12 +716,9 @@ void GourceSettings::importGourceSettings(ConfFile& conffile, ConfSection* gourc
name = data;
#endif
- debugLog("%s => %s", name.c_str(), image_path.c_str());
-
- user_image_map[name] = image_path;
- }
+ debugLog("%s => %s", name.c_str(), image_path.c_str());
- closedir(dp);
+ user_image_map[name] = image_path;
}
}

0 comments on commit 2ba358b

Please sign in to comment.