Пример #1
0
static int mission_menu_handler(listbox *lb, d_event *event, mission_menu *mm)
{
	const char **list = listbox_get_items(lb);
	int citem = listbox_get_citem(lb);

	switch (event->type)
	{
		case EVENT_NEWMENU_SELECTED:
			if (citem >= 0)
			{
				// Chose a mission
				strcpy(GameCfg.LastMission, list[citem]);
				
				if (!load_mission(mm->mission_list + citem))
				{
					nm_messagebox( NULL, 1, TXT_OK, TXT_MISSION_ERROR);
					return 1;	// stay in listbox so user can select another one
				}
			}
			return !(*mm->when_selected)();
			break;

		case EVENT_WINDOW_CLOSE:
			free_mission_list(mm->mission_list);
			d_free(list);
			d_free(mm);
			break;
			
		default:
			break;
	}
	
	return 0;
}
Пример #2
0
// Goober5000
void CFREDDoc::OnFileImportFSM() 
{
	CString fs1_mission_mfc;
	char fs1_mission[MAX_PATH_LEN];
	char *ch;
	char temp[MAX_PATH_LEN];

	// if mission has been modified, offer to save before continuing.
	if (!SaveModified())
		return;

	// set up import dialog
	CFileDialog dlg(TRUE, "fsm", NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR, "FreeSpace Missions (*.fsm)|*.fsm|All files (*.*)|*.*||");
	dlg.m_ofn.lpstrTitle = "Select a mission to import";

	// set initial path
	strcpy(temp, Fred_exe_dir);
	if ((ch = stristr(temp, "FreeSpace2")) >= 0)
	{
		strcpy(ch, "FreeSpace\\Data\\Missions");
		dlg.m_ofn.lpstrInitialDir = temp;
	}

	// get FSM file
	if (dlg.DoModal() != IDOK)
		return;

	fs1_mission_mfc = dlg.GetPathName();

	if (strlen(fs1_mission_mfc) > MAX_PATH_LEN - 1)
	{
		MessageBox(NULL, "Path name is too long", "Error", MB_OK);
		return;
	}

	if (!strlen(fs1_mission_mfc))
	{
		return;
	}

	strcpy(fs1_mission, fs1_mission_mfc);

	// load mission into memory
	if (Briefing_dialog)
		Briefing_dialog->icon_select(-1);  // clean things up first
	if (load_mission(fs1_mission, 1))
		return;

	// ugh - change the file name
	FREDDoc_ptr->SetPathName("Untitled");

	// we haven't saved it yet
	set_modified(TRUE);

	// error check and notify
	if (!Fred_view_wnd->global_error_check())
	{
		Fred_view_wnd->MessageBox("Mission successfully imported with no errors.", "Woohoo!");
	}
}
Пример #3
0
// save mission to a file
BOOL CFREDDoc::OnSaveDocument(LPCTSTR pathname)
{
	CFred_mission_save save;
	char name[1024];
	int len;
	DWORD attrib;
	FILE *fp;

	len = strlen(pathname);
	strcpy(name, pathname);
	if (name[len - 4] == '.')
		len -= 4;

	name[len] = 0;  // drop extension
	while (len--)
		if ((name[len] == '\\') || (name[len] == ':'))
			break;

	strcpy(Mission_filename, name + len + 1);
	Fred_view_wnd->global_error_check();
	if (Briefing_dialog) {
		Briefing_dialog->update_data(1);
		Briefing_dialog->save_editor_state();
	}
	
	if (Event_editor_dlg)
		Fred_main_wnd->MessageBox("Event editor dialog is still open, so changes there won't be saved");

	if (Message_editor_dlg)
		Fred_main_wnd->MessageBox("Message editor dialog is still open, so changes there won't be saved");

	fp = fopen(pathname, "r");
	if (fp) {
		fclose(fp);
		attrib = GetFileAttributes(pathname);
		if (attrib & FILE_ATTRIBUTE_READONLY) {
			Fred_main_wnd->MessageBox("File is read-only.  You need to check it out before saving to it");
			return FALSE;
		}
	}	

	if (save.save_mission_file((char *) pathname)) {
		Fred_main_wnd->MessageBox("An error occured while saving!", NULL, MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	SetModifiedFlag(FALSE);
	if (load_mission((char *) pathname))
		Error(LOCATION, "Failed attempting to reload mission after saving.  Report this bug now!");

	if (Briefing_dialog) {
		Briefing_dialog->restore_editor_state();
		Briefing_dialog->update_data(1);
	}

	return TRUE;
//	return CDocument::OnSaveDocument(pathname);
}
Пример #4
0
//loads the named mission if exists.
//Returns true if mission loaded ok, else false.
int load_mission_by_name(char *mission_name)
{
	int n,i;

	n = build_mission_list(1);

	for (i=0;i<n;i++)
		if (!strcasecmp(mission_name,Mission_list[i].filename))
			return load_mission(i);

	return 0;		//couldn't find mission
}
Пример #5
0
//loads the named mission if exists.
//Returns true if mission loaded ok, else false.
int load_mission_by_name(const char *mission_name)
{
	int i;
	mle *mission_list = build_mission_list(1);
	bool found = 0;

	for (i = 0; i < num_missions; i++)
		if (!stricmp(mission_name, mission_list[i].filename))
			found = load_mission(mission_list + i);

	free_mission_list(mission_list);
	return found;
}
Пример #6
0
int select_mission(int anarchy_mode, const char *message, int (*when_selected)(void))
{
    mle *mission_list = build_mission_list(anarchy_mode);
	int new_mission_num;

    if (num_missions <= 1)
	{
        new_mission_num = load_mission(mission_list) ? 0 : -1;
		free_mission_list(mission_list);
		(*when_selected)();
		
		return (new_mission_num >= 0);
    }
	else
	{
		mission_menu *mm;
        int i, default_mission;
        const char **m;
		
		MALLOC(m, const char *, num_missions);
		if (!m)
		{
			free_mission_list(mission_list);
			return 0;
		}
		
		MALLOC(mm, mission_menu, 1);
		if (!mm)
		{
			d_free(m);
			free_mission_list(mission_list);
			return 0;
		}

		mm->mission_list = mission_list;
		mm->when_selected = when_selected;
		
        default_mission = 0;
        for (i = 0; i < num_missions; i++) {
            m[i] = mission_list[i].mission_name;
            if ( !stricmp( m[i], GameCfg.LastMission ) )
                default_mission = i;
        }

        newmenu_listbox1( message, num_missions, m, 1, default_mission, (int (*)(listbox *, d_event *, void *))mission_menu_handler, mm );
    }

    return 1;	// presume success
}
Пример #7
0
int CFREDDoc::autoload() {
	char name[256], backup_name[256];
	int i, r;
	FILE *fp;

	cf_create_default_path_string(name, sizeof(name) - 1, CF_TYPE_MISSIONS);
	strcat_s(name, MISSION_BACKUP_NAME);
	strcpy_s(backup_name, name);
	strcat_s(name, ".002");

	// Check if Backup.002 exists
	fp = fopen(name, "r");
	if (!fp)
		return 0;
	fclose(fp);

	if (Briefing_dialog) {
		// clean things up first
		Briefing_dialog->icon_select(-1);
	}

	// Load Backup.002
	//	editor_init_mission();  
	r = load_mission(name);
	Update_window = 1;

	// Delete Backup.001
	auto len = strlen(backup_name);
	strcat_s(backup_name, ".001");
	cf_delete(backup_name, CF_TYPE_MISSIONS);

	// Rename Backups. .002 becomes .001, .003 becomes .002, etc.
	for (i = 1; i < BACKUP_DEPTH; i++) {
		sprintf(backup_name + len, ".%.3d", i + 1);
		sprintf(name + len, ".%.3d", i);
		cf_rename(backup_name, name, CF_TYPE_MISSIONS);
		undo_desc[i] = undo_desc[i + 1];
	}

	// Reduce the undo count and check if we can do another undo op.
	Undo_count--;
	check_undo();
	return r;
}
Пример #8
0
// read in a new mission file from disk
BOOL CFREDDoc::OnOpenDocument(LPCTSTR pathname)
{
	char name[1024];
	int i, len;

	if (pathname)
		strcpy(mission_pathname, pathname);

	if (Briefing_dialog)
		Briefing_dialog->icon_select(-1);  // clean things up first

	len = strlen(mission_pathname);
	strcpy(name, mission_pathname);
	if (name[len - 4] == '.')
		len -= 4;

	name[len] = 0;  // drop extension
	i = len;
	while (i--)
		if ((name[i] == '\\') || (name[i] == ':'))
			break;

	strcpy(Mission_filename, name + i + 1);
//	for (i=1; i<=BACKUP_DEPTH; i++) {
//		sprintf(name + len, ".%.3d", i);
//		unlink(name);
//	}

	

	if (load_mission(mission_pathname)) {
		*Mission_filename = 0;
		return FALSE;
	}

	Fred_view_wnd->global_error_check();
	autosave("nothing");
	Undo_count = 0;

	AddToRecentFileList(pathname);

	return TRUE;
}
Пример #9
0
int CFREDDoc::autoload()
{
	char name[256], backup_name[256];
	int i, r, len;
	FILE *fp;

	strcpy(name, current_dir);
	strcat(name, MISSION_BACKUP_NAME);
	strcat(name, ".002");
	
	//strcpy(name, MISSION_BACKUP_NAME);
	//strcat(name, ".002");

	fp = fopen(name, "r");
	if (!fp)
		return 0;

	fclose(fp);
	if (Briefing_dialog)
		Briefing_dialog->icon_select(-1);  // clean things up first

//	editor_init_mission();  
	r = load_mission(name);
	Update_window = 1;

	strcpy(backup_name, current_dir);
	strcat(backup_name, MISSION_BACKUP_NAME);
	len = strlen(backup_name);
	strcat(backup_name, ".001");
	cf_delete(backup_name, CF_TYPE_MISSIONS);

	for (i=1; i<BACKUP_DEPTH; i++) {
		sprintf(backup_name + len, ".%.3d", i + 1);
		sprintf(name + len, ".%.3d", i);
		cf_rename(backup_name, name, CF_TYPE_MISSIONS);
		undo_desc[i] = undo_desc[i + 1];
	}

	Undo_count--;
	check_undo();
	return r;
}
Пример #10
0
void do_new_game_menu()
{
	int new_level_num,player_highest_level;

#ifndef SHAREWARE
	int n_missions = build_mission_list(0);

	if (n_missions > 1) {
		int new_mission_num,i, default_mission;
		char * m[MAX_MISSIONS];

		default_mission = 0;
		for (i=0;i<n_missions;i++) {
			m[i] = Mission_list[i].mission_name;
			if ( !strcasecmp( m[i], config_last_mission ) )	
				default_mission = i;
		}

		new_mission_num = newmenu_listbox1( "New Game\n\nSelect mission", n_missions, m, 1, default_mission, NULL );

		if (new_mission_num == -1)
			return;		//abort!

		strcpy(config_last_mission, m[new_mission_num]  );
		
		if (!load_mission(new_mission_num)) {
			nm_messagebox( NULL, 1, TXT_OK, "Error in Mission file"); 
			return;
		}
	}
#endif

	new_level_num = 1;

	player_highest_level = get_highest_level();

	if (player_highest_level > Last_level)
		player_highest_level = Last_level;

	if (player_highest_level > 1) {
		newmenu_item m[2];
		char info_text[80];
		char num_text[10];
		int choice;

try_again:
		sprintf(info_text,"%s %d",TXT_START_ANY_LEVEL, player_highest_level);

		m[0].type=NM_TYPE_TEXT; m[0].text = info_text;
		m[1].type=NM_TYPE_INPUT; m[1].text_len = 10; m[1].text = num_text;

		strcpy(num_text,"1");

		choice = newmenu_do( NULL, TXT_SELECT_START_LEV, 2, m, NULL );

		if (choice==-1 || m[1].text[0]==0)
			return;

		new_level_num = atoi(m[1].text);

		if (!(new_level_num>0 && new_level_num<=player_highest_level)) {
			m[0].text = TXT_ENTER_TO_CONT;
			nm_messagebox( NULL, 1, TXT_OK, TXT_INVALID_LEVEL); 
			goto try_again;
		}
	}

	Difficulty_level = Player_default_difficulty;

	if (!do_difficulty_menu())
		return;

	gr_palette_fade_out( gr_palette, 32, 0 );

#ifdef PSX_BUILD_TOOLS
	{
		int i;
		for (i=Last_secret_level; i<=Last_level; i++ )	{
			if ( i!=0 )	
				StartNewGame(i);
		}		
	}
#endif

	StartNewGame(new_level_num);

}
Пример #11
0
//returns flag, true means quit menu
void do_option ( int select) 
{
	switch (select) {
		case MENU_NEW_GAME:
			do_new_game_menu();
			break;
		case MENU_GAME:
			break;
		case MENU_DEMO_PLAY:
			{ 
				char demo_file[16];
				if (newmenu_get_filename( TXT_SELECT_DEMO, "*.dem", demo_file, 1 ))	{
					newdemo_start_playback(demo_file);
				}
			}
			break;
		case MENU_LOAD_GAME:
#ifdef SHAREWARE
			do_load_game_menu();
#else
			state_restore_all(0);	
#endif
			break;
		#ifdef EDITOR
		case MENU_EDITOR:
			Function_mode = FMODE_EDITOR;
			init_cockpit();
			break;
		#endif
		case MENU_VIEW_SCORES:
			gr_palette_fade_out( gr_palette,32,0 );
			scores_view(-1);
			break;
		#ifdef SHAREWARE
		case MENU_ORDER_INFO:
			show_order_form();
			break;
		#endif
		case MENU_QUIT:
			#ifdef EDITOR
			if (! SafetyCheck()) break;
			#endif
			gr_palette_fade_out( gr_palette,32,0);
			Function_mode = FMODE_EXIT;
			break;
		case MENU_NEW_PLAYER:
			RegisterPlayer();		//1 == allow escape out of menu
			break;

		case MENU_HELP:
			do_show_help();
			break;

                #ifndef RELEASE

		case MENU_PLAY_SONG:	{
				int i;
				char * m[MAX_SONGS];

				for (i=0;i<MAX_SONGS;i++) {
					m[i] = Songs[i].filename;
				}
				i = newmenu_listbox( "Select Song", MAX_SONGS, m, 1, NULL );

				if ( i > -1 )	{
					songs_play_song( i, 0 );
				}
			}
			break;
		case MENU_LOAD_LEVEL: {
			newmenu_item m;
			char text[10]="";
			int new_level_num;

			m.type=NM_TYPE_INPUT; m.text_len = 10; m.text = text;

			newmenu_do( NULL, "Enter level to load", 1, &m, NULL );

			new_level_num = atoi(m.text);

			if (new_level_num!=0 && new_level_num>=Last_secret_level && new_level_num<=Last_level)	{
				gr_palette_fade_out( gr_palette, 32, 0 );
				StartNewGame(new_level_num);
			}

			break;
		}
                #endif


		case MENU_START_NETGAME:
#ifdef NETWORK
//temp!
#ifndef SHAREWARE
			load_mission(0);
#endif
                        read_player_file();
			network_start_game();
#endif
			break;
		case MENU_JOIN_NETGAME:
//temp!
#ifdef NETWORK
#ifndef SHAREWARE
			load_mission(0);
#endif
                        read_player_file();
			network_join_game();
#endif
			break;
#ifdef NETWORK
		case MENU_IPX_MULTIPLAYER:
			do_ipx_multi_player_menu();
			break;
		case MENU_KALI_MULTIPLAYER:
			do_kali_multi_player_menu();
			break;
#ifdef SUPPORTS_NET_IP
		case MENU_IP_MULTIPLAYER:
			do_ip_multi_player_menu();
			break;
		case MENU_IP_SERV_CONNECT:
			do_ip_serv_connect_menu();
			break;
		case MENU_MANUAL_IP_JOIN:
			do_ip_manual_join_menu();
			break;
#endif
		case MENU_START_SERIAL:
			com_main_menu();
			break;
		case MENU_MULTIPLAYER:
			do_multi_player_menu();
			break;
#endif //NETWORK
		case MENU_CONFIG:
			do_options_menu();
			break;
		case MENU_SHOW_CREDITS:
			gr_palette_fade_out( gr_palette,32,0);
			credits_show();	
			break;
		default:
			Error("Unknown option %d in do_option",select);
			break;
        }

}
Пример #12
0
int LoadCampaignOld(const char *filename, CampaignSettingOld *setting)
{
	FILE *f = NULL;
	int32_t i;
	int err = 0;

	debug(D_NORMAL, "f: %s\n", filename);
	f = fopen(filename, "rb");
	if (f == NULL)
	{
		err = -1;
		goto bail;
	}

	f_read32(f, &i, sizeof(i));
	if (i != CAMPAIGN_MAGIC)
	{
		debug(D_NORMAL, "LoadCampaign - bad file!\n");
		err = -1;
		goto bail;
	}

	f_read32(f, &i, sizeof(i));
	if (i != CAMPAIGN_VERSION)
	{
		debug(D_NORMAL, "LoadCampaign - version mismatch!\n");
		err = -1;
		goto bail;
	}

	f_read(f, setting->title, sizeof(setting->title));
	f_read(f, setting->author, sizeof(setting->author));
	f_read(f, setting->description, sizeof(setting->description));

	f_read32(f, &setting->missionCount, sizeof(int32_t));
	CCALLOC(
		setting->missions,
		setting->missionCount * sizeof *setting->missions);
	debug(D_NORMAL, "No. missions: %d\n", setting->missionCount);
	for (i = 0; i < setting->missionCount; i++)
	{
		load_mission(f, &setting->missions[i]);
	}

	f_read32(f, &setting->characterCount, sizeof(int32_t));
	CCALLOC(
		setting->characters,
		setting->characterCount * sizeof *setting->characters);
	debug(D_NORMAL, "No. characters: %d\n", setting->characterCount);
	for (i = 0; i < setting->characterCount; i++)
	{
		load_character(f, &setting->characters[i]);
	}

bail:
	if (f != NULL)
	{
		fclose(f);
	}
	return err;
}
Пример #13
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;
	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;
}
Пример #14
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;
}
Пример #15
0
void CFREDDoc::OnFileImportFSM() {
	char fs1_mission_path[MAX_PATH_LEN];
	char fs2_mission_path[MAX_PATH_LEN];
	char dest_directory[MAX_PATH + 1];

	// path stuff
	{
		char *ch;

		// get base paths
		strcpy_s(fs1_mission_path, Fred_exe_dir);
		ch = strrchr(fs1_mission_path, DIR_SEPARATOR_CHAR);
		if (ch != NULL)
			*ch = '\0';
		strcpy_s(fs2_mission_path, Fred_exe_dir);
		ch = strrchr(fs2_mission_path, DIR_SEPARATOR_CHAR);
		if (ch != NULL)
			*ch = '\0';

		// estimate the mission path for FS1
		if ((ch = stristr(fs1_mission_path, "FreeSpace2")) != NULL) {
			strcpy(ch, "FreeSpace\\Data\\Missions");
		}

		// estimate the mission path for FS2
		strcat_s(fs2_mission_path, "\\Data\\Missions");
	}

	// if mission has been modified, offer to save before continuing.
	if (!SaveModified())
		return;


	// get location to import from
	CFileDialog dlgFile(TRUE, "fsm", NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_ALLOWMULTISELECT, "FreeSpace Missions (*.fsm)|*.fsm|All files (*.*)|*.*||");
	dlgFile.m_ofn.lpstrTitle = "Select one or more missions to import";
	dlgFile.m_ofn.lpstrInitialDir = fs1_mission_path;

	// get FSM files
	if (dlgFile.DoModal() != IDOK)
		return;

	memset(dest_directory, 0, sizeof(dest_directory));

	// get location to save to    
#if ( _MFC_VER >= 0x0700 )
	//ITEMIDLIST fs2_mission_pidl = {0};

	//SHParseDisplayName(A2CW(fs2_mission_path), NULL, fs2_mission_pidl, 0, 0);

	BROWSEINFO bi;
	bi.hwndOwner = theApp.GetMainWnd()->GetSafeHwnd();
	//bi.pidlRoot = &fs2_mission_pidl;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = dest_directory;
	bi.lpszTitle = "Select a location to save in";
	bi.ulFlags = 0;
	bi.lpfn = NULL;
	bi.lParam = NULL;
	bi.iImage = NULL;

	LPCITEMIDLIST ret_val = SHBrowseForFolder(&bi);

	if (ret_val == NULL)
		return;

	SHGetPathFromIDList(ret_val, dest_directory);
#else
	CFolderDialog dlgFolder(_T("Select a location to save in"), fs2_mission_path, NULL);
	if (dlgFolder.DoModal() != IDOK)
		return;

	strcpy_s(dest_directory, dlgFolder.GetFolderPath());
#endif

	// clean things up first
	if (Briefing_dialog)
		Briefing_dialog->icon_select(-1);

	clear_mission();

	// process all missions
	POSITION pos(dlgFile.GetStartPosition());
	while (pos) {
		char *ch;
		char filename[1024];
		char fs1_path[MAX_PATH_LEN];
		char dest_path[MAX_PATH_LEN];

		CString fs1_path_mfc(dlgFile.GetNextPathName(pos));
		CFred_mission_save save;

		DWORD attrib;
		FILE *fp;


		// path name too long?
		if (strlen(fs1_path_mfc) > MAX_PATH_LEN - 1)
			continue;

		// nothing here?
		if (!strlen(fs1_path_mfc))
			continue;

		// get our mission
		strcpy_s(fs1_path, fs1_path_mfc);

		// load mission into memory
		if (load_mission(fs1_path, MPF_IMPORT_FSM))
			continue;

		// get filename
		ch = strrchr(fs1_path, DIR_SEPARATOR_CHAR) + 1;
		if (ch != NULL)
			strcpy_s(filename, ch);
		else
			strcpy_s(filename, fs1_path);

		// truncate extension
		ch = strrchr(filename, '.');
		if (ch != NULL)
			*ch = '\0';

		// add new extension
		strcat_s(filename, ".fs2");

		strcpy_s(Mission_filename, filename);

		// get new path
		strcpy_s(dest_path, dest_directory);
		strcat_s(dest_path, "\\");
		strcat_s(dest_path, filename);

		// check attributes
		fp = fopen(dest_path, "r");
		if (fp) {
			fclose(fp);
			attrib = GetFileAttributes(dest_path);
			if (attrib & FILE_ATTRIBUTE_READONLY)
				continue;
		}

		// try to save it
		if (save.save_mission_file(dest_path))
			continue;

		// success
	}

	create_new_mission();

	MessageBox(NULL, "Import complete.  Please check the destination folder to verify all missions were imported successfully.", "Status", MB_OK);
	recreate_dialogs();
}
Пример #16
0
int LoadCampaign(
	const char *filename, CampaignSetting *setting,
	int max_missions, int max_characters)
{
	FILE *f = NULL;
	int i;
	int err = CAMPAIGN_OK;
	int numMissions = max_missions;
	int numCharacters = max_characters;

	debug(D_NORMAL, "f: %s\n", filename);
	f = fopen(filename, "rb");
	if (f == NULL)
	{
		err = CAMPAIGN_BADPATH;
		goto bail;
	}

	f_read32(f, &i, sizeof(i));
	if (i != CAMPAIGN_MAGIC)
	{
		debug(D_NORMAL, "LoadCampaign - bad file!\n");
		err = CAMPAIGN_BADFILE;
		goto bail;
	}

	f_read32(f, &i, sizeof(i));
	if (i != CAMPAIGN_VERSION)
	{
		debug(D_NORMAL, "LoadCampaign - version mismatch!\n");
		err = CAMPAIGN_VERSIONMISMATCH;
		goto bail;
	}

	f_read(f, setting->title, sizeof(setting->title));
	f_read(f, setting->author, sizeof(setting->author));
	f_read(f, setting->description, sizeof(setting->description));

	f_read32(f, &setting->missionCount, sizeof(setting->missionCount));

	if (max_missions <= 0)
	{
		size_t size = setting->missionCount * sizeof(struct Mission);
		CCALLOC(setting->missions, size);
		numMissions = setting->missionCount;
	}
	else if (setting->missionCount < max_missions)
	{
		numMissions = setting->missionCount;
	}

	debug(D_NORMAL, "No. missions: %d\n", numMissions);
	for (i = 0; i < numMissions; i++)
	{
		load_mission(f, &setting->missions[i]);
	}

	f_read32(f, &setting->characterCount, sizeof(setting->characterCount));

	if (max_characters <= 0)
	{
		size_t size = setting->characterCount * sizeof(TBadGuy);
		CCALLOC(setting->characters, size);
		numCharacters = setting->characterCount;
	}
	else if (setting->characterCount < max_characters)
	{
		numCharacters = setting->characterCount;
	}

	debug(D_NORMAL, "No. characters: %d\n", numCharacters);
	for (i = 0; i < numCharacters; i++)
	{
		load_character(f, &setting->characters[i]);
	}

bail:
	if (f != NULL)
	{
		fclose(f);
	}
	return err;
}