Exemplo n.º 1
0
void build_save_file_list (void)
{
	session_list_data_type
		*game_session;

	directory_file_list
		*directory_listing;

	ui_object
		*new_item;

	int
		valid_file;

	char
		*p,
		filename [256],
		extension [8];

	ui_object_destroy_list_items (save_file_list);

	game_session = get_current_game_session ();

	ASSERT (game_session);

	sprintf (full_filename, "%s//%s//*.", game_session->data_path, game_session->campaign_directory);

	sprintf (extension, "%s", game_type_extensions [get_game_type ()]);

	extension [2] = extension [1];
	extension [1] = extension [0];
	extension [0] = 'S';

	strcat (full_filename, extension);

	directory_listing = get_first_directory_file (full_filename);

	if (directory_listing)
	{
		valid_file = TRUE;

		while (valid_file)
		{
			if (get_directory_file_type (directory_listing) == DIRECTORY_FILE_TYPE_FILE)
			{
				sprintf (filename, get_directory_file_filename (directory_listing));

				p = strchr (filename, '.');

				if (p)
				{
					*p = '\0';
				}

				new_item = add_to_pop_up_list (filename, save_file_list, NULL, ENTITY_INDEX_DONT_CARE, UI_FONT_ARIAL_16, ui_ingame_live_text_colour);

				set_ingame_ui_object_mouse_over_properties (new_item);
			}

			valid_file = get_next_directory_file (directory_listing);
		}

		destroy_directory_file_list (directory_listing);
	}

	resize_pop_up_list (save_file_list);
}
Exemplo n.º 2
0
void recursive_check_campaign_files (const char *directory, session_list_data_type **list, const char *extension)
{

	session_list_types
		session_type;

	directory_file_list
		*warzone_file,
		*directory_listing;

	unsigned int
		i,
		upper;

	int
		value,
		valid_file,
		season;

	static char
		operator_ [64],
		variable [64],
		temp_warzone_name [128],
		*warzone_name,
		warzone_path [1024],
		directory_search_path [1024];

	//
	// First, go through any files in this directory.
	//

	sprintf (directory_search_path, "%s\\*.%s", directory, extension);

	// Jabberwock 0400201 Session filter revised

	//VJ 050123 small bug fix: check for lowercase AND uppercase
	if ((strstr(directory, "CAMP01") || strstr(directory, "camp01")) && command_line_session_filter)
	{
		sprintf(warzone_path, "%s\\*.chc", directory);

		warzone_file = get_first_directory_file(warzone_path);

		sprintf(temp_warzone_name, "%s", get_directory_file_filename (warzone_file));

	//  Vadim 051120, if chc filename has spaces, capitalize every word

		for (upper=1, i = 0; i < (strlen (temp_warzone_name) - 4); i++)
		{
			if (upper)
			{
				temp_warzone_name[i] = toupper (temp_warzone_name[i]);
				upper=0;
			}
			else if (isspace(temp_warzone_name[i])) {
					upper=1;
			}
			else
			{
				temp_warzone_name[i] = tolower (temp_warzone_name[i]);
			}
		}

		temp_warzone_name[i] = '\0';

		for (i = 0; i < (strlen (directory) - 7); i++)
		{
			warzone_path[i] = directory[i];
		}

		warzone_path[i] = '\0';


		add_session (temp_warzone_name, SESSION_LIST_TYPE_FILTER, 1, NULL, warzone_path, NULL, NULL, temp_warzone_name, list, NULL, SESSION_SEASON_INVALID);
	}


	directory_listing = get_first_directory_file (directory_search_path);

	// JB 030313 Enable running out of separate directories
	if (!directory_listing)
	{
		char fn[1024];
		fn[0] = 0;
		strcpy(fn, comanche_hokum_installation_path);
		strcat(fn, "\\common\\");
		strcat(fn, directory_search_path);

		directory_listing = get_first_directory_file ( fn );
	}

	if (directory_listing)
	{

		valid_file = TRUE;

		while (valid_file)
		{

			session_type = SESSION_LIST_TYPE_HOST;

			if (get_directory_file_type (directory_listing) == DIRECTORY_FILE_TYPE_FILE)
			{

				FILE
					*file_ptr;

				file_tags
					tag;

				int
					end_flag;

				static char
					*ptr,
					*last_ptr,
					path [1024],
					full_filename [1024],
					campaign_title [1024],
					campaign_directory [32],
					campaign_filename [1024];

				//
				// Add campaign file to list
				//

				sprintf (full_filename, "%s\\%s", directory, get_directory_file_filename (directory_listing));

				file_ptr = safe_fopen (full_filename, "r");

				end_flag = FALSE;

				warzone_name = NULL;

				season = SESSION_SEASON_INVALID;

				while (!end_flag)
				{

					tag = (file_tags) get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG);

					switch (tag)
					{

						case FILE_TAG_WARZONE_NAME:
						{

							get_next_file_string (file_ptr, temp_warzone_name, sizeof (temp_warzone_name));

							warzone_name = temp_warzone_name;

							break;
						}

						case FILE_TAG_TITLE:
						{

							get_next_file_string (file_ptr, campaign_title, sizeof (campaign_title));

							//
							// Create data path, ie strip off the last directory name
							// N.B. valid data directories are in any directory below 'MAPS'.
							//

							strcpy (path, directory);

							ptr = strstr (path, "\\maps\\");

							ptr += strlen ("\\maps\\");

							while (ptr = strstr (ptr, "\\"))
							{

								ptr += strlen ("\\");

								last_ptr = ptr;
							}

							sprintf (campaign_directory, "%s", last_ptr);

							sprintf (campaign_filename, "%s", get_directory_file_filename (directory_listing));

							last_ptr -= strlen ("\\");

							*last_ptr = '\0';

							break;
						}

						case FILE_TAG_LANGUAGE_TEXT_START:
						{

							// skip script till correct language

							while (tag = (file_tags) get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG))
							{

								#if (LANGUAGE == LANGUAGE_FRENCH)

								if (tag == FILE_TAG_LANGUAGE_FRENCH)
								{

									break;
								}
								#elif (LANGUAGE == LANGUAGE_GERMAN)

								if (tag == FILE_TAG_LANGUAGE_GERMAN)
								{

									break;
								}
								#elif (LANGUAGE == LANGUAGE_ITALIAN)

								if (tag == FILE_TAG_LANGUAGE_ITALIAN)
								{

									break;
								}
								#elif (LANGUAGE == LANGUAGE_SPANISH)

								if (tag == FILE_TAG_LANGUAGE_SPANISH)
								{

									break;
								}
								#else //LANGUAGE_ENGLISH

								if (tag == FILE_TAG_LANGUAGE_ENGLISH)
								{

									break;
								}
								#endif

								if (tag == FILE_TAG_LANGUAGE_TEXT_STOP)
								{

									break;
								}
							}

							break;
						}

						case FILE_TAG_LANGUAGE_TEXT_END:
						{

							// skip script till end of languages

							while (tag = (file_tags) get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG))
							{

								if (tag == FILE_TAG_LANGUAGE_TEXT_STOP)
								{

									break;
								}
							}

							break;
						}

						case FILE_TAG_CAMPAIGN_DATA:
						{

							while (tag = (file_tags) get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG))
							{

								if (tag == FILE_TAG_END)
								{

									break;
								}
							}

							break;
						}

						case FILE_TAG_SAVED_CAMPAIGN:
						{

							session_type = SESSION_LIST_TYPE_RESTORE;

							break;
						}

						case FILE_TAG_IF:
						{

							ASSERT (get_current_player_log ());

							get_next_file_word (file_ptr, variable, sizeof (variable));

							get_next_file_word (file_ptr, operator_, sizeof (operator_));

							value = get_next_file_int (file_ptr);

							if (!if_file_tag_variable (variable, operator_, value))
							{

								// skip script till endif

								while (tag = (file_tags) get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG))
								{

									if ((tag == FILE_TAG_ENDIF) || (tag == FILE_TAG_END))
									{

										break;
									}
								}
							}

							break;
						}

						case FILE_TAG_ENDIF:
						{

							break;
						}

						case FILE_TAG_SEASON:
						{
							// 15JUN09 Casm retrieving season earlier
							season = get_next_file_int (file_ptr);

							break;
						}

						case FILE_TAG_CAMPAIGN_REQUIRES_APACHE_HAVOC:
						{
							debug_log("session filter: campaign_title %s", campaign_title);
							// VJ 050123 aphavoc install hack, do not close map if it exists but EEAH is not offcially installed
							if (!global_aphavoc_maps)
							{
								if (!get_global_apache_havoc_installed ())
								{

									end_flag = TRUE;

									debug_log ("SESSION: Campaign %s required Apache-Havoc to be installed", campaign_title);

									break;
								}
							}
						}

						case FILE_TAG_END:
						case FILE_TAG_UNKNOWN:
						{

							end_flag = TRUE;

							if ((!command_line_session_filter) || (strcmp(session_filter_value, "root") != 0))
							{
								// 15JUN09 Casm retrieving season earlier
								const char
									*title;
								// if host get the Translated campaign name
								// not hosted game so just use the name
								title = session_type == SESSION_LIST_TYPE_HOST ? get_trans (campaign_title) :  campaign_title;
								if (session_type == SESSION_LIST_TYPE_HOST || (session_type == SESSION_LIST_TYPE_MASTER) || (session_type == SESSION_LIST_TYPE_RESTORE))
								{
									add_session (title, session_type, 1, NULL, path, campaign_directory, campaign_filename, warzone_name, list, NULL, season);
								}
							}
							// Jabberwock 0400201 ends

							break;
						}
					}
				}

				fclose (file_ptr);
			}

			valid_file = get_next_directory_file (directory_listing);
		}

		destroy_directory_file_list (directory_listing);
	}

	//
	// Next, go through any directories, recursing into them.
	//

	sprintf (directory_search_path, "%s\\*", directory);

	directory_listing = get_first_directory_file (directory_search_path);

	// JB 030313 Enable running out of separate directories
	if (!directory_listing)
	{
		char fn[1024];
		fn[0] = 0;
		strcpy(fn, comanche_hokum_installation_path);
		strcat(fn, "\\common\\");
		strcat(fn, directory_search_path);

		directory_listing = get_first_directory_file ( fn );
	}

	if (directory_listing)
	{

		valid_file = TRUE;

		while (valid_file)
		{

			if (get_directory_file_type (directory_listing) == DIRECTORY_FILE_TYPE_DIRECTORY)
			{

				if ((strcmp (get_directory_file_filename (directory_listing), ".") != 0) &&
						(strcmp (get_directory_file_filename (directory_listing), "..") != 0))
				{

					char
						full_directory [1024];

					//
					// Create the full directory name
					//

					sprintf (full_directory, "%s\\%s", directory, get_directory_file_filename (directory_listing));

					//
					// Recurse into this directory
					//

					recursive_check_campaign_files (full_directory, list, extension);
				}
			}

			valid_file = get_next_directory_file (directory_listing);
		}

		destroy_directory_file_list (directory_listing);
	}
}