예제 #1
0
bool CampaignEntryTryLoad(
	CampaignEntry *entry, const char *path, GameMode mode)
{
	char *buf;
	int numMissions;
	if (!IsCampaignOK(path, &buf, &numMissions))
	{
		return false;
	}
	// cap length of title
	size_t maxLen = 70;
	if (strlen(buf) > maxLen)
	{
		buf[maxLen] = '\0';
	}
	char title[256];
	sprintf(title, "%s (%d)", buf, numMissions);
	CampaignEntryInit(entry, title, mode);
	CSTRDUP(entry->Filename, PathGetBasename(path));
	// Get relative path for the campaign entry, so when we transmit it to
	// network clients they can load it regardless of install path
	char pathBuf[CDOGS_PATH_MAX];
	RelPathFromCWD(pathBuf, path);
	CSTRDUP(entry->Path, pathBuf);
	entry->NumMissions = numMissions;
	CFREE(buf);
	return true;
}
예제 #2
0
bool CampaignEntryTryLoad(
	CampaignEntry *entry, const char *path, campaign_mode_e mode)
{
	char *buf;
	int numMissions;
	if (!IsCampaignOK(path, &buf, &numMissions))
	{
		return false;
	}
	// cap length of title
	size_t maxLen = 70;
	if (strlen(buf) > maxLen)
	{
		buf[maxLen] = '\0';
	}
	char title[256];
	sprintf(title, "%s (%d)", buf, numMissions);
	CampaignEntryInit(entry, title, mode);
	CSTRDUP(entry->Filename, PathGetBasename(path));
	CSTRDUP(entry->Path, path);
	entry->IsBuiltin = false;
	entry->NumMissions = numMissions;
	CFREE(buf);
	return true;
}
예제 #3
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);
}