2 * psychlops_io_file.cpp
3 * Psychlops Standard Library (Universal)
5 * Last Modified 2006/10/10 by Kenchi HOSOKAWA
6 * (C) 2006 Kenchi HOSOKAWA, Kazushi MARUYA and Takao SATO
10 #include <sys/types.h>
15 #include "../ApplicationInterfaces/psychlops_app.h"
16 #include "psychlops_io_file.h"
20 File::PATH_ID_STRING::PATH_ID_STRING(const char * id_str) : id_string(id_str), id_string_length(id_string.length()) {};
\r
21 File::PATH_ID_STRING File::STANDARD_PATH[6] = {"%APP%", "%RESOURCES%", "%USER_HOME%", "%USER_SETTING%", "%USER_DOCUMENTS%", "%USER_DOCUMENTS_ROOT%"};
\r
23 bool File::appname_initialized = false;
\r
25 std::string File::decodePath(const char * path) {
26 return decodePath(std::string(path));
28 std::string File::decodePath(const std::string &path) {
29 // const int PROHOBITED_CNT = 9;
\r
30 // const char PROHOBITED[PROHOBITED_CNT] = {';',',',':','*','?','\"','<','>','|'};
\r
31 const int PROHOBITED_CNT = 7;
\r
32 const char PROHOBITED[PROHOBITED_CNT] = {';',',','*','?','<','>','|'};
\r
33 std::string decoded_path("");
\r
34 decoded_path.append(path);
39 decoded_path = replacePathDevider(decoded_path);
\r
41 for(int i=0; i<PROHOBITED_CNT; i++) {
43 loc=decoded_path.find(PROHOBITED[i],0);
44 if(loc==std::string::npos) { break; }
45 decoded_path.erase(loc, 1);
48 for(int i=0; i<6; i++) {
49 loc=decoded_path.find(STANDARD_PATH[i].id_string,0);
50 if(loc!=std::string::npos) {
\r
51 decoded_path.replace(loc, STANDARD_PATH[i].id_string_length, STANDARD_PATH[i].path);
\r
55 char filenametimestamp[64];
58 strftime( filenametimestamp, 64, "%Y%m%d_%H%M%S", localtime(&nowtime) );
60 loc = decoded_path.find( "%TIME_", 0 );
61 if(loc==std::string::npos) { break; }
62 decoded_path.erase(loc, 6);
63 decoded_path.insert(loc,filenametimestamp);
66 loc = decoded_path.find( "%EXPNAME_", 0 );
67 if(loc==std::string::npos) { break; }
68 decoded_path.erase(loc, 9);
69 decoded_path.insert(loc,AppInfo::expname);
77 } /* <- namespace Psycholops */