virtual void OnTimeout() { /* Widgets WID_SL_DELETE_SELECTION and WID_SL_SAVE_GAME only exist when saving to a file. */ if (this->fop != SLO_SAVE) return; if (this->IsWidgetLowered(WID_SL_DELETE_SELECTION)) { // Delete button clicked if (!FiosDelete(this->filename_editbox.text.buf)) { ShowErrorMessage(STR_ERROR_UNABLE_TO_DELETE_FILE, INVALID_STRING_ID, WL_ERROR); } else { this->InvalidateData(SLIWD_RESCAN_FILES); /* Reset file name to current date on successful delete */ if (this->abstract_filetype == FT_SAVEGAME) GenerateFileName(); } } else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) { FiosMakeSavegameName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name)); if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) { ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveGameConfirmationCallback); } else { _switch_mode = SM_SAVE_GAME; } } else { FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name)); if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) { ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveHeightmapConfirmationCallback); } else { _switch_mode = SM_SAVE_HEIGHTMAP; } } /* In the editor set up the vehicle engines correctly (date might have changed) */ if (_game_mode == GM_EDITOR) StartupEngines(); } }
bool ScriptScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename) { free(this->main_script); this->main_script = strdup(filename); if (this->main_script == NULL) return false; free(this->tar_file); if (tar_filename != NULL) { this->tar_file = strdup(tar_filename); if (this->tar_file == NULL) return false; } else { this->tar_file = NULL; } const char *end = this->main_script + strlen(this->main_script) + 1; char *p = strrchr(this->main_script, PATHSEPCHAR); if (p == NULL) { p = this->main_script; } else { /* Skip over the path separator character. We don't need that. */ p++; } strecpy(p, "main.nut", end); if (!FioCheckFileExists(filename, this->subdir) || !FioCheckFileExists(this->main_script, this->subdir)) return false; /* We don't care if one of the other scripts failed to load. */ this->engine->ResetCrashed(); this->engine->LoadScript(filename); return true; }
/** * Find the GRFID of a given grf, and calculate its md5sum. * @param config grf to fill. * @param is_static grf is static. * @param subdir the subdirectory to search in. * @return Operation was successfully completed. */ bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir) { if (!FioCheckFileExists(config->filename, subdir)) { config->status = GCS_NOT_FOUND; return false; } /* Find and load the Action 8 information */ LoadNewGRFFile(config, CONFIG_SLOT, GLS_FILESCAN, subdir); config->SetSuitablePalette(); config->FinalizeParameterInfo(); /* Skip if the grfid is 0 (not read) or 0xFFFFFFFF (ttdp system grf) */ if (config->ident.grfid == 0 || config->ident.grfid == 0xFFFFFFFF || config->IsOpenTTDBaseGRF()) return false; if (is_static) { /* Perform a 'safety scan' for static GRFs */ LoadNewGRFFile(config, 62, GLS_SAFETYSCAN, subdir); /* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */ if (HasBit(config->flags, GCF_UNSAFE)) return false; } return CalcGRFMD5Sum(config, subdir); }
/* Find the GRFID and calculate the md5sum */ bool FillGRFDetails(GRFConfig *config, bool is_static) { if (!FioCheckFileExists(config->filename)) { config->status = GCS_NOT_FOUND; return false; } /* Find and load the Action 8 information */ LoadNewGRFFile(config, CONFIG_SLOT, GLS_FILESCAN); /* Skip if the grfid is 0 (not read) or 0xFFFFFFFF (ttdp system grf) */ if (config->grfid == 0 || config->grfid == 0xFFFFFFFF || config->IsOpenTTDBaseGRF()) return false; if (is_static) { /* Perform a 'safety scan' for static GRFs */ LoadNewGRFFile(config, 62, GLS_SAFETYSCAN); /* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */ if (HasBit(config->flags, GCF_UNSAFE)) return false; } config->windows_paletted = (_use_palette == PAL_WINDOWS); return CalcGRFMD5Sum(config); }
static void SelectSongToPlay() { uint i = 0; uint j = 0; memset(_cur_playlist, 0, sizeof(_cur_playlist)); do { const char *filename = BaseMusic::GetUsedSet()->files[_playlists[_msf.playlist][i] - 1].filename; /* We are now checking for the existence of that file prior * to add it to the list of available songs */ if (!StrEmpty(filename) && FioCheckFileExists(filename, GM_DIR)) { _cur_playlist[j] = _playlists[_msf.playlist][i]; j++; } } while (_playlists[_msf.playlist][++i] != 0 && j < lengthof(_cur_playlist) - 1); /* Do not shuffle when on the intro-start window, as the song to play has to be the original TTD Theme*/ if (_msf.shuffle && _game_mode != GM_MENU) { i = 500; do { uint32 r = InteractiveRandom(); byte *a = &_cur_playlist[GB(r, 0, 5)]; byte *b = &_cur_playlist[GB(r, 8, 5)]; if (*a != 0 && *b != 0) { byte t = *a; *a = *b; *b = t; } } while (--i); } }
static bool OpenPNGFile(const char *filename, uint32 id, bool mask) { char png_file[MAX_PATH]; /* Add path separator after 'sprites' if not present */ const char *sep = (filename[0] == PATHSEPCHAR) ? "" : PATHSEP; snprintf(png_file, sizeof(png_file), "sprites%s%s" PATHSEP "%d%s.png", sep, filename, id, mask ? "m" : ""); if (FioCheckFileExists(png_file)) { FioOpenFile(PNG_SLOT, png_file); return true; } /* TODO -- Add TAR support */ return false; }
/** * Load all translations that we know of. * @return Container with all (compiled) translations. */ GameStrings *LoadTranslations() { const GameInfo *info = Game::GetInfo(); char filename[512]; strecpy(filename, info->GetMainScript(), lastof(filename)); char *e = strrchr(filename, PATHSEPCHAR); if (e == NULL) return NULL; e++; // Make 'e' point after the PATHSEPCHAR strecpy(e, "lang" PATHSEP "english.txt", lastof(filename)); if (!FioCheckFileExists(filename, GAME_DIR)) return NULL; GameStrings *gs = new GameStrings(); try { *gs->raw_strings.Append() = ReadRawLanguageStrings(filename); /* Scan for other language files */ LanguageScanner scanner(gs, filename); strecpy(e, "lang" PATHSEP, lastof(filename)); size_t len = strlen(filename); const char *tar_filename = info->GetTarFile(); TarList::iterator iter; if (tar_filename != NULL && (iter = _tar_list[GAME_DIR].find(tar_filename)) != _tar_list[GAME_DIR].end()) { /* The main script is in a tar file, so find all files that * are in the same tar and add them to the langfile scanner. */ TarFileList::iterator tar; FOR_ALL_TARS(tar, GAME_DIR) { /* Not in the same tar. */ if (tar->second.tar_filename != iter->first) continue; /* Check the path and extension. */ if (tar->first.size() <= len || tar->first.compare(0, len, filename) != 0) continue; if (tar->first.compare(tar->first.size() - 4, 4, ".txt") != 0) continue; scanner.AddFile(tar->first.c_str(), 0, tar_filename); } } else { /* Scan filesystem */ scanner.Scan(filename); } gs->Compile(); return gs; } catch (...) {
static void SelectSongToPlay() { uint i = 0; uint j = 0; memset(_cur_playlist, 0, sizeof(_cur_playlist)); do { /* File is the index into the file table of the music set. The play list uses 0 as 'no entry', * so we need to subtract 1. In case of 'no entry' (file = -1), just skip adding it outright. */ int file = _playlists[_settings_client.music.playlist][i] - 1; if (file >= 0) { const char *filename = BaseMusic::GetUsedSet()->files[file].filename; /* We are now checking for the existence of that file prior * to add it to the list of available songs */ if (!StrEmpty(filename) && FioCheckFileExists(filename, BASESET_DIR)) { _cur_playlist[j] = _playlists[_settings_client.music.playlist][i]; j++; } } } while (_playlists[_settings_client.music.playlist][++i] != 0 && j < lengthof(_cur_playlist) - 1); /* Do not shuffle when on the intro-start window, as the song to play has to be the original TTD Theme*/ if (_settings_client.music.shuffle && _game_mode != GM_MENU) { i = 500; do { uint32 r = InteractiveRandom(); byte *a = &_cur_playlist[GB(r, 0, 5)]; byte *b = &_cur_playlist[GB(r, 8, 5)]; if (*a != 0 && *b != 0) { byte t = *a; *a = *b; *b = t; } } while (--i); } }