Пример #1
0
void LoadAllCampaigns(custom_campaigns_t *campaigns)
{
	char buf[CDOGS_PATH_MAX];

	CampaignListInit(&campaigns->campaignList);
	CampaignListInit(&campaigns->dogfightList);

	GetDataFilePath(buf, CDOGS_CAMPAIGN_DIR);
	LOG(LM_MAIN, LL_INFO, "Load campaigns from dir %s...", buf);
	LoadCampaignsFromFolder(
		&campaigns->campaignList,
		"",
		buf,
		GAME_MODE_NORMAL);

	GetDataFilePath(buf, CDOGS_DOGFIGHT_DIR);
	LOG(LM_MAIN, LL_INFO, "Load dogfights from dir %s...", buf);
	LoadCampaignsFromFolder(
		&campaigns->dogfightList,
		"",
		buf,
		GAME_MODE_DOGFIGHT);

	LOG(LM_MAIN, LL_INFO, "Load quick play...");
	LoadQuickPlayEntry(&campaigns->quickPlayEntry);
}
Пример #2
0
void LoadAllCampaigns(custom_campaigns_t *campaigns)
{
	CampaignListInit(&campaigns->campaignList);
	CampaignListInit(&campaigns->dogfightList);

	printf("\nCampaigns:\n");

	LoadBuiltinCampaigns(&campaigns->campaignList);
	LoadCampaignsFromFolder(
		&campaigns->campaignList,
		"",
		GetDataFilePath(CDOGS_CAMPAIGN_DIR),
		0);

	printf("\nDogfights:\n");

	LoadBuiltinDogfights(&campaigns->dogfightList);
	LoadCampaignsFromFolder(
		&campaigns->dogfightList,
		"",
		GetDataFilePath(CDOGS_DOGFIGHT_DIR),
		1);

	LoadQuickPlayEntry(&campaigns->quickPlayEntry);

	printf("\n");
}
Пример #3
0
static void LoadCampaignsFromFolder(
	campaign_list_t *list, const char *name, const char *path,
	const GameMode mode)
{
	tinydir_dir dir;
	int i;

	CSTRDUP(list->Name, name);
	if (tinydir_open_sorted(&dir, path) == -1)
	{
		printf("Cannot load campaigns from path %s\n", path);
		return;
	}

	for (i = 0; i < (int)dir.n_files; i++)
	{
		tinydir_file file;
		tinydir_readfile_n(&dir, &file, i);

		// Ignore campaigns that start with a ~
		// These are autosaved

		const bool isArchive =
			strcmp(file.extension, "cdogscpn") == 0 ||
			strcmp(file.extension, "CDOGSCPN") == 0;
		if (file.is_dir && !isArchive &&
			strcmp(file.name, ".") != 0 && strcmp(file.name, "..") != 0)
		{
			campaign_list_t subFolder;
			CampaignListInit(&subFolder);
			LoadCampaignsFromFolder(&subFolder, file.name, file.path, mode);
			CArrayPushBack(&list->subFolders, &subFolder);
		}
		else if ((file.is_reg || isArchive) && file.name[0] != '~')
		{
			CampaignEntry entry;
			if (CampaignEntryTryLoad(&entry, file.path, mode))
			{
				CArrayPushBack(&list->list, &entry);
			}
		}
	}

	tinydir_close(&dir);
}
Пример #4
0
void LoadCampaignsFromFolder(
	campaign_list_t *list, const char *name, const char *path, campaign_mode_e mode)
{
	tinydir_dir dir;
	int i;

	strcpy(list->name, name);
	if (tinydir_open_sorted(&dir, path) == -1)
	{
		printf("Cannot load campaigns from path %s\n", path);
		return;
	}

	for (i = 0; i < dir.n_files; i++)
	{
		tinydir_file file;
		tinydir_readfile_n(&dir, &file, i);

		if (file.is_dir &&
			strcmp(file.name, ".") != 0 && strcmp(file.name, "..") != 0)
		{
			campaign_list_t *subFolder;
			list->numSubFolders++;
			CREALLOC(list->subFolders, sizeof(campaign_list_t)*list->numSubFolders);
			subFolder = &list->subFolders[list->numSubFolders-1];
			CampaignListInit(subFolder);
			LoadCampaignsFromFolder(subFolder, file.name, file.path, mode);
		}
		else if (file.is_reg)
		{
			char title[256];
			if (IsCampaignOK(file.path, title))
			{
				AddCustomCampaignEntry(list, file.name, file.path, title, mode);
			}
		}
	}

	tinydir_close(&dir);
}