//ini File の基本 #include "profile.h" #include #include #include #include #include #include //=============================================== Profile::Profile(void){} //=============================================== //---------------------------------- Profile::Profile(char *IniFileName) { ProfileOpen(IniFileName); } //=============================================== //ファイルがちゃんとあれば0 存在しなければ-1 int Profile::ProfileOpen(char *IniFileName) { IniFile[0] = 0; // 内容に ":\" があればIniFileNameはフルパスとして扱う if(strchr(IniFileName, ':') || strchr(IniFileName, '\\')) { strcpy(IniFile, IniFileName); } else { //カレントディレクトリのフルパスを作成する #ifndef __WIN32__ char buf[MAXPATH+1]; IniFile[0] = (char)('A' + getdisk()); strcpy(&IniFile[1], ":\\"); getcurdir(0, buf); strcat(IniFile, buf); if(IniFile[strlen(IniFile)-1] != '\\') strcat(IniFile, "\\"); strcat(IniFile, IniFileName); #else GetCurrentDirectory(MAXPATH, IniFile); if(IniFile[strlen(IniFile)-1] != '\\') strcat(IniFile, "\\"); strcat(IniFile, IniFileName); #endif } //Open Check int handle; if((handle=open(IniFile, O_RDONLY)) == -1) { return -1; } else close(handle); return 0; } //=============================================== char *Profile::GetString(char *section, char *key, char *defstr, char *buf, int size) { GetPrivateProfileString(section, key, defstr, buf, size, IniFile); return buf; } //=============================================== char *Profile::SetString(char *section, char *key, char *buf) { WritePrivateProfileString(section, key, buf, IniFile); return buf; } //=============================================== int Profile::GetInt(char *section, char *key, int defnum) { char buf[16]; wsprintf(buf,"%d", defnum); GetString(section, key, buf, buf, sizeof(buf)); return atoi(buf); } //=============================================== void Profile::GetInt(char *section, char *key, int defnum, int &d) { d = GetInt(section, key, defnum); } //=============================================== int Profile::SetInt(char *section, char *key, int num) { char buf[16]; wsprintf(buf,"%d", num); SetString(section, key, buf); return num; } //=============================================== double Profile::GetDbl(char *section, char *key, double defnum) { char buf[32]; sprintf(buf,"%f", defnum); GetString(section, key, buf, buf, sizeof(buf)); return atof(buf); } //=============================================== void Profile::GetDbl(char *section, char *key, double defnum, double &d) { d = GetDbl(section, key, defnum); } //=============================================== double Profile::SetDbl(char *section, char *key, double num) { char buf[32]; sprintf(buf,"%f", num); SetString(section, key, buf); return num; } //=============================================== //===============================================