comparison system/system_config.cc @ 53:ddbcbd000206

* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons * ParseMoji moved to TextStream * Some cleaning (0 -> NULL when needed, removal of useless returns, ...)
author thib
date Sun, 19 Apr 2009 11:44:05 +0000
parents 15a18fbe6f21
children d7cde171a1de
comparison
equal deleted inserted replaced
52:15a18fbe6f21 53:ddbcbd000206
68 else return strcmp(a.str, b.str); 68 else return strcmp(a.str, b.str);
69 } 69 }
70 else return a.hash < b.hash; 70 else return a.hash < b.hash;
71 } 71 }
72 }; 72 };
73
73 HashStr::HashStr(const char* s ) { 74 HashStr::HashStr(const char* s ) {
74 if (s == NULL || s[0] == '\0') { 75 if (s == NULL || s[0] == '\0') {
75 str = NULL; 76 str = NULL;
76 hash = 0; 77 hash = 0;
77 return; /* invalid string */ 78 return; /* invalid string */
674 675
675 /************************************************ 676 /************************************************
676 ** AyuSysConfig のコンストラクタ: 677 ** AyuSysConfig のコンストラクタ:
677 ** 全ての config 項目を初期化する 678 ** 全ての config 項目を初期化する
678 */ 679 */
680
681 AyuSysConfig * AyuSysConfig::_singleton = NULL;
682
683 AyuSysConfig* AyuSysConfig::GetInstance(void)
684 {
685 if (_singleton == NULL)
686 _singleton = new AyuSysConfig;
687 return _singleton;
688 }
689
690 void AyuSysConfig::Quit(void)
691 {
692 if (_singleton != NULL) {
693 delete _singleton;
694 _singleton = NULL;
695 }
696 }
697
698
679 AyuSysConfig::AyuSysConfig(void) { 699 AyuSysConfig::AyuSysConfig(void) {
680 int i; 700 int i;
681 701
682 change_flag = 1; dirty_flag = 0; 702 change_flag = 1; dirty_flag = 0;
683 str_config = new AyuSysConfigString; 703 str_config = new AyuSysConfigString;
887 return 0; 907 return 0;
888 } 908 }
889 909
890 bool AyuSysConfig::LoadInitFile(void) 910 bool AyuSysConfig::LoadInitFile(void)
891 { 911 {
912 FileSearcher* file_searcher = FileSearcher::GetInstance();
913
892 char buf[1024]; int i; 914 char buf[1024]; int i;
893 char* tokens[MAXTOKEN]; int token_deal; int buf_ptr; 915 char* tokens[MAXTOKEN]; int token_deal; int buf_ptr;
894 int numbers[MAXVARS]; 916 int numbers[MAXVARS];
895 917
896 ARCINFO* info = file_searcher.Find(FILESEARCH::ROOT, "gameexe.ini"); 918 ARCINFO* info = file_searcher->Find(FileSearcher::ROOT, "gameexe.ini");
897 if (info == NULL) return false; 919 if (info == NULL) return false;
898 int size = info->Size(); 920 int size = info->Size();
899 unsigned char* buf_orig = (unsigned char*)info->Read(); 921 unsigned char* buf_orig = (unsigned char*)info->Read();
900 if (size <= 0 || buf_orig == NULL) { 922 if (size <= 0 || buf_orig == NULL) {
901 delete info; return false; 923 delete info; return false;
998 SetOrigParaStr(tokens[0], tokens[1]); 1020 SetOrigParaStr(tokens[0], tokens[1]);
999 goto parse_end; 1021 goto parse_end;
1000 } else if (strncmp(tokens[0],"#DIRC.",6) == 0) { 1022 } else if (strncmp(tokens[0],"#DIRC.",6) == 0) {
1001 if (token_deal != 3) goto parse_error; 1023 if (token_deal != 3) goto parse_error;
1002 /* ファイル形式の指定 */ 1024 /* ファイル形式の指定 */
1003 FILESEARCH::FILETYPE type; 1025 FileSearcher::FILETYPE type;
1004 char* name = tokens[0]+6; 1026 char* name = tokens[0]+6;
1005 if (strcmp(name, "PDT") == 0) type = FILESEARCH::PDT; 1027 if (strcmp(name, "PDT") == 0) type = FileSearcher::PDT;
1006 else if (strcmp(name, "G00") == 0) type = FILESEARCH::PDT; 1028 else if (strcmp(name, "G00") == 0) type = FileSearcher::PDT;
1007 else if (strcmp(name, "GRP") == 0) type = FILESEARCH::PDT; 1029 else if (strcmp(name, "GRP") == 0) type = FileSearcher::PDT;
1008 else if (strcmp(name, "TXT") == 0) type = FILESEARCH::SCN; 1030 else if (strcmp(name, "TXT") == 0) type = FileSearcher::SCN;
1009 else if (strcmp(name, "ANM") == 0) type = FILESEARCH::ANM; 1031 else if (strcmp(name, "ANM") == 0) type = FileSearcher::ANM;
1010 else if (strcmp(name, "ARD") == 0) type = FILESEARCH::ARD; 1032 else if (strcmp(name, "ARD") == 0) type = FileSearcher::ARD;
1011 else if (strcmp(name, "CUR") == 0) type = FILESEARCH::CUR; 1033 else if (strcmp(name, "CUR") == 0) type = FileSearcher::CUR;
1012 else if (strcmp(name, "WAV") == 0) type = FILESEARCH::WAV; 1034 else if (strcmp(name, "WAV") == 0) type = FileSearcher::WAV;
1013 else if (strcmp(name, "KOE") == 0) type = FILESEARCH::KOE; 1035 else if (strcmp(name, "KOE") == 0) type = FileSearcher::KOE;
1014 else if (strcmp(name, "GAN") == 0) type = FILESEARCH::GAN; 1036 else if (strcmp(name, "GAN") == 0) type = FileSearcher::GAN;
1015 else goto parse_error; /* 他に ALL,ROOT,MID,KOE,BGM。たぶん、存在しない */ 1037 else goto parse_error; /* 他に ALL,ROOT,MID,KOE,BGM。たぶん、存在しない */
1016 if (tokens[2][0] == 'N') { /* directory */ 1038 if (tokens[2][0] == 'N') { /* directory */
1017 file_searcher.SetFileInformation(type, FILESEARCH::ATYPE_DIR, tokens[1]); 1039 file_searcher->SetFileInformation(type, FileSearcher::ATYPE_DIR, tokens[1]);
1018 dprintf(("set file directory; type %s, directory %s\n",name,tokens[1])); 1040 dprintf(("set file directory; type %s, directory %s\n",name,tokens[1]));
1019 } else if (tokens[2][0] == 'P' && tokens[2][1] == ':') { /* アーカイブ */ 1041 } else if (tokens[2][0] == 'P' && tokens[2][1] == ':') { /* アーカイブ */
1020 file_searcher.SetFileInformation(type, FILESEARCH::ATYPE_ARC, tokens[2]+2); 1042 file_searcher->SetFileInformation(type, FileSearcher::ATYPE_ARC, tokens[2]+2);
1021 dprintf(("set file archive; type %s, file %s\n",name,tokens[2]+2)); 1043 dprintf(("set file archive; type %s, file %s\n",name,tokens[2]+2));
1022 } else goto parse_error; 1044 } else goto parse_error;
1023 goto parse_end; 1045 goto parse_end;
1024 } 1046 }
1025 if (strncmp(tokens[0],"#ADRC.",6) == 0) { 1047 if (strncmp(tokens[0],"#ADRC.",6) == 0) {
1026 if (token_deal != 3) goto parse_error; 1048 if (token_deal != 3) goto parse_error;
1027 /* ファイル形式の指定 */ 1049 /* ファイル形式の指定 */
1028 FILESEARCH::FILETYPE type; 1050 FileSearcher::FILETYPE type;
1029 char* name = tokens[0]+6; 1051 char* name = tokens[0]+6;
1030 if (strcmp(name, "PDT") == 0) type = FILESEARCH::PDT; 1052 if (strcmp(name, "PDT") == 0) type = FileSearcher::PDT;
1031 else if (strcmp(name, "G00") == 0) type = FILESEARCH::PDT; 1053 else if (strcmp(name, "G00") == 0) type = FileSearcher::PDT;
1032 else if (strcmp(name, "GRP") == 0) type = FILESEARCH::PDT; 1054 else if (strcmp(name, "GRP") == 0) type = FileSearcher::PDT;
1033 else if (strcmp(name, "TXT") == 0) type = FILESEARCH::SCN; 1055 else if (strcmp(name, "TXT") == 0) type = FileSearcher::SCN;
1034 else if (strcmp(name, "ANM") == 0) type = FILESEARCH::ANM; 1056 else if (strcmp(name, "ANM") == 0) type = FileSearcher::ANM;
1035 else if (strcmp(name, "ARD") == 0) type = FILESEARCH::ARD; 1057 else if (strcmp(name, "ARD") == 0) type = FileSearcher::ARD;
1036 else if (strcmp(name, "CUR") == 0) type = FILESEARCH::CUR; 1058 else if (strcmp(name, "CUR") == 0) type = FileSearcher::CUR;
1037 else if (strcmp(name, "WAV") == 0) type = FILESEARCH::WAV; 1059 else if (strcmp(name, "WAV") == 0) type = FileSearcher::WAV;
1038 else if (strcmp(name, "KOE") == 0) type = FILESEARCH::KOE; 1060 else if (strcmp(name, "KOE") == 0) type = FileSearcher::KOE;
1039 else if (strcmp(name, "GAN") == 0) type = FILESEARCH::GAN; 1061 else if (strcmp(name, "GAN") == 0) type = FileSearcher::GAN;
1040 else goto parse_error; /* 他に ALL,ROOT,MID,KOE,BGM。たぶん、存在しない */ 1062 else goto parse_error; /* 他に ALL,ROOT,MID,KOE,BGM。たぶん、存在しない */
1041 if (tokens[2][0] == 'N') { /* directory */ 1063 if (tokens[2][0] == 'N') { /* directory */
1042 file_searcher.AppendFileInformation(type, FILESEARCH::ATYPE_DIR, tokens[1]); 1064 file_searcher->AppendFileInformation(type, FileSearcher::ATYPE_DIR, tokens[1]);
1043 dprintf(("set file directory; type %s, directory %s\n",name,tokens[1])); 1065 dprintf(("set file directory; type %s, directory %s\n",name,tokens[1]));
1044 } else if (tokens[2][0] == 'P' && tokens[2][1] == ':') { /* アーカイブ */ 1066 } else if (tokens[2][0] == 'P' && tokens[2][1] == ':') { /* アーカイブ */
1045 file_searcher.AppendFileInformation(type, FILESEARCH::ATYPE_ARC, tokens[2]+2); 1067 file_searcher->AppendFileInformation(type, FileSearcher::ATYPE_ARC, tokens[2]+2);
1046 dprintf(("set file archive; type %s, file %s\n",name,tokens[2]+2)); 1068 dprintf(("set file archive; type %s, file %s\n",name,tokens[2]+2));
1047 } else if (tokens[2][0] == 'R' && tokens[2][1] == ':') { /* それ散るアーカイブ */ 1069 } else if (tokens[2][0] == 'R' && tokens[2][1] == ':') { /* それ散るアーカイブ */
1048 file_searcher.AppendFileInformation(type, FILESEARCH::ATYPE_ARC, tokens[2]+2); 1070 file_searcher->AppendFileInformation(type, FileSearcher::ATYPE_ARC, tokens[2]+2);
1049 dprintf(("set file archive; type %s, file %s\n",name,tokens[2]+2)); 1071 dprintf(("set file archive; type %s, file %s\n",name,tokens[2]+2));
1050 } else goto parse_error; 1072 } else goto parse_error;
1051 goto parse_end; 1073 goto parse_end;
1052 } 1074 }
1053 if (strncmp(tokens[0],"#FOLDNAME.",10) == 0) { 1075 if (strncmp(tokens[0],"#FOLDNAME.",10) == 0) {
1054 if (token_deal != 3) goto parse_error; 1076 if (token_deal != 3) goto parse_error;
1055 /* ファイル形式の指定 */ 1077 /* ファイル形式の指定 */
1056 FILESEARCH::FILETYPE type; 1078 FileSearcher::FILETYPE type;
1057 char* name = tokens[0]+10; 1079 char* name = tokens[0]+10;
1058 if (strcmp(name, "PDT") == 0) type = FILESEARCH::PDT; 1080 if (strcmp(name, "PDT") == 0) type = FileSearcher::PDT;
1059 else if (strcmp(name, "G00") == 0) type = FILESEARCH::PDT; 1081 else if (strcmp(name, "G00") == 0) type = FileSearcher::PDT;
1060 else if (strcmp(name, "GRP") == 0) type = FILESEARCH::PDT; 1082 else if (strcmp(name, "GRP") == 0) type = FileSearcher::PDT;
1061 else if (strcmp(name, "TXT") == 0) type = FILESEARCH::SCN; 1083 else if (strcmp(name, "TXT") == 0) type = FileSearcher::SCN;
1062 else if (strcmp(name, "ANM") == 0) type = FILESEARCH::ANM; 1084 else if (strcmp(name, "ANM") == 0) type = FileSearcher::ANM;
1063 else if (strcmp(name, "ARD") == 0) type = FILESEARCH::ARD; 1085 else if (strcmp(name, "ARD") == 0) type = FileSearcher::ARD;
1064 else if (strcmp(name, "CUR") == 0) type = FILESEARCH::CUR; 1086 else if (strcmp(name, "CUR") == 0) type = FileSearcher::CUR;
1065 else if (strcmp(name, "WAV") == 0) type = FILESEARCH::WAV; 1087 else if (strcmp(name, "WAV") == 0) type = FileSearcher::WAV;
1066 else if (strcmp(name, "BGM") == 0) type = FILESEARCH::BGM; 1088 else if (strcmp(name, "BGM") == 0) type = FileSearcher::BGM;
1067 else if (strcmp(name, "GAN") == 0) type = FILESEARCH::GAN; 1089 else if (strcmp(name, "GAN") == 0) type = FileSearcher::GAN;
1068 else goto parse_error; /* 他に ALL,ROOT,MID,KOE,BGM。たぶん、存在しない */ 1090 else goto parse_error; /* 他に ALL,ROOT,MID,KOE,BGM。たぶん、存在しない */
1069 if (tokens[2][0] == '0') { /* directory */ 1091 if (tokens[2][0] == '0') { /* directory */
1070 file_searcher.AppendFileInformation(type, FILESEARCH::ATYPE_DIR, tokens[1]); 1092 file_searcher->AppendFileInformation(type, FileSearcher::ATYPE_DIR, tokens[1]);
1071 dprintf(("set file directory; type %s, directory %s\n",name,tokens[1])); 1093 dprintf(("set file directory; type %s, directory %s\n",name,tokens[1]));
1072 } else if (tokens[2][0] == '1' && tokens[2][1] == ':') { /* アーカイブ */ 1094 } else if (tokens[2][0] == '1' && tokens[2][1] == ':') { /* アーカイブ */
1073 file_searcher.AppendFileInformation(type, FILESEARCH::ATYPE_SCN2k, tokens[2]+2); 1095 file_searcher->AppendFileInformation(type, FileSearcher::ATYPE_SCN2k, tokens[2]+2);
1074 dprintf(("set file archive; type %s, file %s\n",name,tokens[2]+2)); 1096 dprintf(("set file archive; type %s, file %s\n",name,tokens[2]+2));
1075 } else goto parse_error; 1097 } else goto parse_error;
1076 goto parse_end; 1098 goto parse_end;
1077 } 1099 }
1078 if (strcmp(tokens[0], "#CDTRACK") == 0) { 1100 if (strcmp(tokens[0], "#CDTRACK") == 0) {