OSDN Git Service

first
[psychlops/cpp.git] / psychlops / core / devices / psychlops_io_file.cpp
1 /*
2  *  psychlops_io_file.cpp
3  *  Psychlops Standard Library (Universal)
4  *
5  *  Last Modified 2006/10/10 by Kenchi HOSOKAWA
6  *  (C) 2006 Kenchi HOSOKAWA, Kazushi MARUYA and Takao SATO
7  */
8
9
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <time.h>
13 #include <string>
14
15 #include "../ApplicationInterfaces/psychlops_app.h"
16 #include "psychlops_io_file.h"
17
18 namespace Psychlops {
19
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
22 \r
23         bool File::appname_initialized = false;\r
24
25         std::string File::decodePath(const char * path) {
26                 return decodePath(std::string(path));
27         }
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);
35                 unsigned int loc;
36
37                 initialize_appname();
38 \r
39                 decoded_path = replacePathDevider(decoded_path);\r
40
41                 for(int i=0; i<PROHOBITED_CNT; i++) {
42                         for(;;) {
43                                 loc=decoded_path.find(PROHOBITED[i],0);
44                                 if(loc==std::string::npos) { break; }
45                                 decoded_path.erase(loc, 1);
46                         }
47                 }
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
52                         }
53                 }
54
55                 char filenametimestamp[64];
56                 time_t nowtime;
57                 time(&nowtime);
58                 strftime( filenametimestamp, 64, "%Y%m%d_%H%M%S", localtime(&nowtime) );
59                 for(;;) {
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);
64                 };
65                 for(;;) {
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);
70                 };
71
72                 return decoded_path;
73         }
74
75
76
77 }       /*      <- namespace Psycholops         */