Exemplo n.º 1
0
static void openrct2_copy_files_over(const utf8 *originalDirectory, const utf8 *newDirectory, const utf8 *extension)
{
	utf8 *ch, filter[MAX_PATH], oldPath[MAX_PATH], newPath[MAX_PATH];
	int fileEnumHandle;
	file_info fileInfo;

	if (!platform_ensure_directory_exists(newDirectory)) {
		log_error("Could not create directory %s.", newDirectory);
		return;
	}

	// Create filter path
	safe_strncpy(filter, originalDirectory, MAX_PATH);
	ch = strchr(filter, '*');
	if (ch != NULL)
		*ch = 0;
	strcat(filter, "*");
	strcat(filter, extension);

	fileEnumHandle = platform_enumerate_files_begin(filter);
	while (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) {
		safe_strncpy(newPath, newDirectory, MAX_PATH);
		strcat(newPath, fileInfo.path);

		safe_strncpy(oldPath, originalDirectory, MAX_PATH);
		ch = strchr(oldPath, '*');
		if (ch != NULL)
			*ch = 0;
		strcat(oldPath, fileInfo.path);

		if (!platform_file_exists(newPath))
			platform_file_copy(oldPath, newPath, false);
	}
	platform_enumerate_files_end(fileEnumHandle);

	fileEnumHandle = platform_enumerate_directories_begin(originalDirectory);
	while (platform_enumerate_directories_next(fileEnumHandle, filter)) {
		safe_strncpy(newPath, newDirectory, MAX_PATH);
		strcat(newPath, filter);

		safe_strncpy(oldPath, originalDirectory, MAX_PATH);
		ch = strchr(oldPath, '*');
		if (ch != NULL)
			*ch = 0;
		strcat(oldPath, filter);

		if (!platform_ensure_directory_exists(newPath)) {
			log_error("Could not create directory %s.", newPath);
			return;
		}
		openrct2_copy_files_over(oldPath, newPath, extension);
	}
	platform_enumerate_directories_end(fileEnumHandle);
}
Exemplo n.º 2
0
    void GetAvailableThemes(List<AvailableTheme> * outThemes)
    {
        Guard::ArgumentNotNull(outThemes);

        outThemes->Clear();

        NumPredefinedThemes = 0;
        for (const UITheme * * predefinedTheme = PredefinedThemes; *predefinedTheme != nullptr; predefinedTheme++)
        {
            AvailableTheme theme;
            String::Set(theme.Path, sizeof(theme.Path), String::Empty);
            String::Set(theme.Name, sizeof(theme.Name), (*predefinedTheme)->Name);
            outThemes->Add(theme);

            NumPredefinedThemes++;
        }

        utf8 themesPattern[MAX_PATH];
        GetThemePath(themesPattern, sizeof(themesPattern));
        Path::Append(themesPattern, sizeof(themesPattern), "*.json");

        int handle = platform_enumerate_files_begin(themesPattern);
        if (handle != INVALID_HANDLE)
        {
            file_info fileInfo;
            while (platform_enumerate_files_next(handle, &fileInfo))
            {
                AvailableTheme theme;
                Path::GetFileNameWithoutExtension(theme.Name, sizeof(theme.Name), fileInfo.path);
                GetThemeFileName(theme.Path, sizeof(theme.Path), theme.Name);
                
                outThemes->Add(theme);

                if (Path::Equals(CurrentThemePath, fileInfo.path))
                {
                    ActiveAvailableThemeIndex = outThemes->GetCount() - 1;
                }
            }
            platform_enumerate_files_end(handle);
        }
    }
Exemplo n.º 3
0
static void window_loadsave_populate_list(rct_window *w, int includeNewItem, const char *directory, const char *extension)
{
	int i;
	int sortStartIndex = 0;
	int listItemCapacity = 8;
	loadsave_list_item *listItem;
	char filter[MAX_PATH];
	
	safe_strcpy(_directory, directory, sizeof(_directory));
	if (_extension != extension) {
		safe_strcpy(_extension, extension, sizeof(_extension));
		_extension[sizeof(_extension) - 1] = '\0';
	}
	_shortenedDirectory[0] = '\0';

	safe_strcpy(filter, directory, sizeof(filter));
	strncat(filter, "*", sizeof(filter) - strnlen(filter, MAX_PATH) - 1);
	strncat(filter, extension, sizeof(filter) - strnlen(filter, MAX_PATH) - 1);

	if (_listItems != NULL)
		free(_listItems);
	_listItems = (loadsave_list_item*)malloc(listItemCapacity * sizeof(loadsave_list_item));
	_listItemsCount = 0;
	
	window_loadsave_widgets[WIDX_NEW].type = includeNewItem?WWT_CLOSEBOX:WWT_EMPTY; // Hide/Show "new" button
	if(directory[0]=='\0' && platform_get_drives()!=0) // List Windows drives
	{
		w->disabled_widgets |= (1<<WIDX_NEW) | (1<<WIDX_UP);
		for (int x = 0; x < 32; x++){
			if (listItemCapacity <= _listItemsCount) {
				listItemCapacity *= 2;
				_listItems = realloc(_listItems, listItemCapacity * sizeof(loadsave_list_item));
			}

			if (platform_get_drives() & (1 << (x))){
				listItem = &_listItems[_listItemsCount];
				memset(listItem->path, '\0', MAX_PATH);
				listItem->path[0] = 'A' + x;
				listItem->path[1] = ':';
				listItem->path[2] = platform_get_path_separator();
				strcpy(listItem->name, listItem->path);
				listItem->type = TYPE_DIRECTORY;
				_listItemsCount++;
			}
		}
	}
	else
	{
		//Get parent directory
		int directoryLength = strlen(directory);
		char separator = platform_get_path_separator();
		for(i = directoryLength-2; i>=0; i--)
		{
			if(directory[i]==separator)
				break;
		}
		safe_strcpy(_parentDirectory, directory, sizeof(_parentDirectory));
		_parentDirectory[i+1] = '\0';
		if(_parentDirectory[0]=='\0' && platform_get_drives()==0)
			w->disabled_widgets |= (1<<WIDX_UP);
		else
			w->disabled_widgets &= ~(1<<WIDX_UP);
		w->disabled_widgets &= ~(1<<WIDX_NEW);
		file_info fileInfo;
		int fileEnumHandle;
		const char *src;
		char *dst;
		char *last_dot_in_filename;
		char subDir[MAX_PATH];
		
		fileEnumHandle = platform_enumerate_directories_begin(directory);
		while (platform_enumerate_directories_next(fileEnumHandle, subDir)){
			if (listItemCapacity <= _listItemsCount) {
				listItemCapacity *= 2;
				_listItems = realloc(_listItems, listItemCapacity * sizeof(loadsave_list_item));
			}

			listItem = &_listItems[_listItemsCount];
			memset(listItem->path, '\0', MAX_PATH);
			safe_strcpy(listItem->path, directory, MAX_PATH);
			strncat(listItem->path, subDir, MAX_PATH - strnlen(listItem->path, MAX_PATH) - 1);
			safe_strcpy(listItem->name, subDir, sizeof(listItem->name));
			listItem->type = TYPE_DIRECTORY;
			_listItemsCount++;
		}
		platform_enumerate_files_end(fileEnumHandle);

		fileEnumHandle = platform_enumerate_files_begin(filter);
		while (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) {
			if (listItemCapacity <= _listItemsCount) {
				listItemCapacity *= 2;
				_listItems = realloc(_listItems, listItemCapacity * sizeof(loadsave_list_item));
			}

			listItem = &_listItems[_listItemsCount];
			safe_strcpy(listItem->path, directory, sizeof(listItem->path));
			strncat(listItem->path, fileInfo.path, sizeof(listItem->path) - strnlen(listItem->path, MAX_PATH) - 1);
			listItem->type = TYPE_FILE;
			listItem->date_modified = platform_file_get_modified_time(listItem->path);

			src = fileInfo.path;
			dst = listItem->name;
			last_dot_in_filename = strrchr(fileInfo.path, '.');
			assert(last_dot_in_filename != NULL);
			i = 0;
			while (src < last_dot_in_filename && i < sizeof(listItem->name) - 1) {
				*dst++ = *src++;
				i++;
			}
			*dst = '\0';

			_listItemsCount++;
		}
		platform_enumerate_files_end(fileEnumHandle);
		window_loadsave_sort_list(sortStartIndex, _listItemsCount - 1);
	}
}