//returns 1 if file read ok, else 0 int read_mission_file(mle *mission, char *filename, int location) { char filename2[100]; PHYSFS_file *mfile; switch (location) { case ML_MISSIONDIR: strcpy(filename2,MISSION_DIR); break; default: Int3(); //fall through case ML_CURDIR: strcpy(filename2,""); break; } strcat(filename2,filename); mfile = PHYSFSX_openReadBuffered(filename2); if (mfile) { char *p; char temp[PATH_MAX], *ext; strcpy(temp,filename); p = strrchr(temp, '/'); // get the filename at the end of the path if (!p) p = temp; else p++; if ((ext = strchr(p, '.')) == NULL) return 0; //missing extension // look if it's .mn2 or .msn mission->descent_version = (ext[3] == '2') ? 2 : 1; *ext = 0; //kill extension mission->path = d_strdup(temp); mission->anarchy_only_flag = 0; mission->filename = mission->path + (p - temp); mission->location = location; p = get_parm_value("name",mfile); if (!p) { //try enhanced mission PHYSFSX_fseek(mfile,0,SEEK_SET); p = get_parm_value("xname",mfile); } if (!p) { //try super-enhanced mission! PHYSFSX_fseek(mfile,0,SEEK_SET); p = get_parm_value("zname",mfile); } if (p) { char *t; if ((t=strchr(p,';'))!=NULL) *t=0; t = p + strlen(p)-1; while (isspace(*t)) *t-- = 0; // remove trailing whitespace if (strlen(p) > MISSION_NAME_LEN) p[MISSION_NAME_LEN] = 0; strncpy(mission->mission_name, p, MISSION_NAME_LEN + 1); } else { PHYSFS_close(mfile); d_free(mission->path); return 0; } p = get_parm_value("type",mfile); //get mission type if (p) mission->anarchy_only_flag = istok(p,"anarchy"); PHYSFS_close(mfile); return 1; } return 0; }
//fills in the global list of missions. Returns the number of missions //in the list. If anarchy_mode set, don't include non-anarchy levels. //if there is only one mission, this function will call load_mission on it. int build_mission_list(int anarchy_mode) { int count=0; char missionspec[256]; d_glob_t glob_ret; //fill in built-in level #ifndef DEST_SAT strcpy(Mission_list[0].filename,""); //no filename for builtin strcpy(Mission_list[0].mission_name,"Descent: First Strike"); count = 1; #endif strcpy(missionspec, AltHogDir); strcat(missionspec, "*.msn"); //now search for levels on disk if ( !d_glob(missionspec, &glob_ret) && glob_ret.gl_pathc) { int j; for (j = 0; j < (int) glob_ret.gl_pathc && (count < MAX_MISSIONS); j++) { FILE *mfile; int is_anarchy; char temp[13], *t; char openfile[128]; //added/edited on 9/5/99 by Victor Rachels for \ or / if ((t = strrchr(glob_ret.gl_pathv[j], USEDSLASH))) //end this section edit - VR t++; else t = glob_ret.gl_pathv[j]; if (strlen(t) > 12) continue; strcpy(temp, t); if ((t = strchr(temp,'.')) == NULL) continue; *t = 0; //kill extension strncpy( Mission_list[count].filename, temp, MISSION_FILENAME_LEN ); Mission_list[count].anarchy_only_flag = is_anarchy = 0; //added/edited on 9/5/99 by Victor Rachels for windows open #ifdef __WINDOWS__ sprintf(openfile,"%s%s",AltHogDir,glob_ret.gl_pathv[j]); #else sprintf(openfile,"%s",glob_ret.gl_pathv[j]); #endif mfile = fopen(openfile, "rt"); //end this section add/edit - VR if (mfile) { char *p; p = get_parm_value("name",mfile); if (p) { char *t; if ((t=strchr(p,';'))!=NULL) *t=0; t = p + strlen(p)-1; while (isspace(*t)) t--; strncpy(Mission_list[count].mission_name,p,MISSION_NAME_LEN); } else { fclose(mfile); continue; //abort this mission file } p = get_parm_value("type",mfile); //get mission type if (p) Mission_list[count].anarchy_only_flag = is_anarchy = istok(p,"anarchy"); fclose(mfile); if (!anarchy_mode && is_anarchy) continue; //skip this mission count++; } } d_globfree(&glob_ret); } #ifdef USE_CD if ( strlen(destsat_cdpath) ) { int i; char temp_spec[128]; strcpy( temp_spec, destsat_cdpath ); strcat( temp_spec, "*.msn" ); if ( !d_glob(temp_spec, &glob_ret) && glob_ret.gl_pathc) { int j; for (j = 0; j < glob_ret.gl_pathc && (count < MAX_MISSIONS); j++) { FILE *mfile; int is_anarchy; char temp[13], *t; //added/edited on 9/5/99 by Victor Rachels for \ or / if ((t = strrchr(glob_ret.gl_pathv[j], USEDSLASH))) //end this section edit - VR t++; else t = glob_ret.gl_pathv[j]; if (strlen(t) > 12) continue; strcpy(temp, t); if ((t = strchr(temp,'.')) == NULL) continue; *t = 0; //kill extension for (i=0; i<count; i++ ) { if (!strcasecmp( Mission_list[i].filename, temp)) break; } if ( i < count ) continue; // Don't use same mission twice! strncpy( Mission_list[count].filename, temp, MISSION_FILENAME_LEN ); Mission_list[count].anarchy_only_flag = is_anarchy = 0; mfile = fopen(glob_ret.gl_pathv[j], "rt"); if (mfile) { char *p; p = get_parm_value("name",mfile); if (p) { char *t; if ((t=strchr(p,';'))!=NULL) *t=0; t = p + strlen(p)-1; while (isspace(*t)) t--; strncpy(Mission_list[count].mission_name,p,MISSION_NAME_LEN); } else { fclose(mfile); continue; //abort this mission file } p = get_parm_value("type",mfile); //get mission type if (p) Mission_list[count].anarchy_only_flag = is_anarchy = istok(p,"anarchy"); fclose(mfile); if (!anarchy_mode && is_anarchy) continue; //skip this mission count++; } } d_glob_free(&glob_ret); } } #endif if (count>1) qsort(&Mission_list[1],count-1,sizeof(*Mission_list),(int (*)(const void *, const void *))ml_sort_func); load_mission(0); //set built-in mission as default return count; }
//fills in the global list of missions. Returns the number of missions //in the list. If anarchy_mode set, don't include non-anarchy levels. //if there is only one mission, this function will call load_mission on it. int build_mission_list(int anarchy_mode) { int count=0; DIR *dir; struct dirent *ent; char path[FILENAME_MAX]; //fill in built-in level #ifndef DEST_SAT strcpy(Mission_list[0].filename,""); //no filename for builtin strcpy(Mission_list[0].mission_name,"Descent: First Strike"); count = 1; #endif //now search for levels on disk #ifndef ANDROID_NDK if ((dir = opendir( Document_path )) != NULL) { while ((ent = readdir( dir )) != NULL && count<MAX_MISSIONS) { FILE *mfile; int is_anarchy; char temp[13],*t; strcpy(temp,ent->d_name); if ((t = strchr(temp,'.')) == NULL) continue; *t = 0; //kill extension strncpy( Mission_list[count].filename, temp, 9 ); Mission_list[count].anarchy_only_flag = is_anarchy = 0; sprintf(path, "%s/%s", Document_path, ent->d_name); mfile = fopen(path,"rt"); if (mfile) { char *p; p = get_parm_value("name",mfile); if (p) { char *t; if ((t=strchr(p,';'))!=NULL) *t=0; t = p + strlen(p)-1; while (isspace(*t)) t--; strncpy(Mission_list[count].mission_name,p,MISSION_NAME_LEN); } else { fclose(mfile); continue; //abort this mission file } p = get_parm_value("type",mfile); //get mission type if (p) Mission_list[count].anarchy_only_flag = is_anarchy = istok(p,"anarchy"); fclose(mfile); if (!anarchy_mode && is_anarchy) continue; //skip this mission count++; } } } #endif #ifdef USE_CD if ( strlen(destsat_cdpath) ) { int i; char temp_spec[128]; strcpy( temp_spec, destsat_cdpath ); strcat( temp_spec, "*.MSN" ); if( !_dos_findfirst( temp_spec, 0, &find ) ) { do { FILE *mfile; int is_anarchy; char temp[13],*t; strcpy(temp,find.name); if ((t = strchr(temp,'.')) == NULL) continue; *t = 0; //kill extension for (i=0; i<count; i++ ) { if (!stricmp( Mission_list[i].filename, temp)) break; } if ( i < count ) continue; // Don't use same mission twice! strncpy( Mission_list[count].filename, temp, 9 ); Mission_list[count].anarchy_only_flag = is_anarchy = 0; mfile = fopen(find.name,"rt"); if (!mfile) { strcpy( temp_spec, destsat_cdpath ); strcat( temp_spec, find.name ); mfile = fopen(temp_spec,"rt"); } if (mfile) { char *p; p = get_parm_value("name",mfile); if (p) { char *t; if ((t=strchr(p,';'))!=NULL) *t=0; t = p + strlen(p)-1; while (isspace(*t)) t--; strncpy(Mission_list[count].mission_name,p,MISSION_NAME_LEN); } else { fclose(mfile); continue; //abort this mission file } p = get_parm_value("type",mfile); //get mission type if (p) Mission_list[count].anarchy_only_flag = is_anarchy = istok(p,"anarchy"); fclose(mfile); if (!anarchy_mode && is_anarchy) continue; //skip this mission count++; } } while( !_dos_findnext( &find ) && count<MAX_MISSIONS); } } #endif if (count>1) qsort(&Mission_list[1],count-1,sizeof(*Mission_list),ml_sort_func); load_mission(0); //set built-in mission as default return count; }
static int read_mission_file(mission_list_type &mission_list, mission_candidate_search_path &pathname) { if (auto mfile = PHYSFSX_openReadBuffered(pathname.data())) { char *p; char *ext; p = strrchr(pathname.data(), '/'); if (!p) p = pathname.data(); if ((ext = strchr(p, '.')) == NULL) return 0; //missing extension mission_list.emplace_back(); mle *mission = &mission_list.back(); mission->path.assign(pathname.data(), ext); #if defined(DXX_BUILD_DESCENT_II) // look if it's .mn2 or .msn mission->descent_version = (ext[3] == MISSION_EXTENSION_DESCENT_II[3]) ? Mission::descent_version_type::descent2 : Mission::descent_version_type::descent1; #endif mission->anarchy_only_flag = 0; mission->filename = next(begin(mission->path), mission->path.find_last_of('/') + 1); PHYSFSX_gets_line_t<80> buf; p = get_parm_value(buf, "name",mfile); #if defined(DXX_BUILD_DESCENT_II) if (!p) { //try enhanced mission PHYSFSX_fseek(mfile,0,SEEK_SET); p = get_parm_value(buf, "xname",mfile); } if (!p) { //try super-enhanced mission! PHYSFSX_fseek(mfile,0,SEEK_SET); p = get_parm_value(buf, "zname",mfile); } if (!p) { //try extensible-enhanced mission! PHYSFSX_fseek(mfile,0,SEEK_SET); p = get_parm_value(buf, "!name",mfile); } #endif if (p) { char *t; if ((t=strchr(p,';'))!=NULL) *t=0; t = p + strlen(p)-1; while (isspace(*t)) *t-- = 0; // remove trailing whitespace mission->mission_name.copy_if(p, mission->mission_name.size() - 1); } else { mission_list.pop_back(); return 0; } { PHYSFSX_gets_line_t<4096> temp; if (PHYSFSX_fgets(temp,mfile)) { if (istok(temp,"type")) { p = get_value(temp); //get mission type if (p) mission->anarchy_only_flag = istok(p,"anarchy"); } } } return 1; } return 0; }