Skip to content

Commit

Permalink
Merge commit 'f5a50a874f5d074ddb0644eb4e8b5e9b029adf08' into jgrpp
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/fileio.cpp
#	src/fileio_func.h
#	src/industry_cmd.cpp
#	src/ini.cpp
#	src/openttd.cpp
#	src/os/windows/win32_main.cpp
#	src/settingsgen/settingsgen.cpp
#	src/strgen/strgen.cpp
#	src/strings.cpp
  • Loading branch information
JGRennison committed Jun 10, 2024
2 parents 64fdbff + f5a50a8 commit feeea06
Show file tree
Hide file tree
Showing 26 changed files with 175 additions and 138 deletions.
2 changes: 1 addition & 1 deletion src/console_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ DEF_CONSOLE_CMD(ConRemove)
_console_file_list_savegame.ValidateFileList();
const FiosItem *item = _console_file_list_savegame.FindItem(file);
if (item != nullptr) {
if (unlink(item->name.c_str()) != 0) {
if (!FioRemove(item->name)) {
IConsolePrint(CC_ERROR, "Failed to delete '{}'.", item->name);
}
} else {
Expand Down
10 changes: 2 additions & 8 deletions src/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
#include <string>
#include <sstream>

#ifdef _WIN32
# include <windows.h>
#else
# include <unistd.h>
#endif /* _WIN32 */

#include "safeguards.h"

std::string _ini_videodriver; ///< The video driver a stored in the configuration file.
Expand Down Expand Up @@ -130,7 +124,7 @@ bool DriverFactoryBase::SelectDriverImpl(const std::string &name, Driver::Type t
* hardware acceleration. */
auto filename = FioFindFullPath(BASE_DIR, HWACCELERATION_TEST_FILE);
if (!filename.empty()) {
unlink(filename.c_str());
FioRemove(filename);

Debug(driver, 1, "Probing {} driver '{}' skipped due to earlier crash", GetDriverTypeName(type), d->name);

Expand Down Expand Up @@ -217,7 +211,7 @@ void DriverFactoryBase::MarkVideoDriverOperational()
* and as we are operational now, remove the hardware acceleration
* test-file. */
auto filename = FioFindFullPath(BASE_DIR, HWACCELERATION_TEST_FILE);
if (!filename.empty()) unlink(filename.c_str());
if (!filename.empty()) FioRemove(filename);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/fileio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,21 @@ void FioCreateDirectory(const std::string &name)
#endif
}

/**
* Remove a file.
* @param filename Filename to remove.
* @return true iff the file was removed.
*/
bool FioRemove(const std::string &filename)
{
if (unlink(filename.c_str()) != 0) {
Debug(misc, 0, "Removing {} failed: {}", filename, StrErrorDumper().GetLast());
return false;
}

return true;
}

/**
* Renames a file from oldname to newname.
* @param oldname file name to rename from
Expand Down
1 change: 1 addition & 0 deletions src/fileio_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ std::string FioFindFullPath(Subdirectory subdir, const std::string &filename);
std::string FioGetDirectory(Searchpath sp, Subdirectory subdir);
std::string FioFindDirectory(Subdirectory subdir);
void FioCreateDirectory(const std::string &name);
bool FioRemove(const std::string &filename);
bool FioRenameFile(const std::string &oldname, const std::string &newname);

const char *FiosGetScreenshotDir();
Expand Down
3 changes: 1 addition & 2 deletions src/fios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ std::string FiosMakeHeightmapName(const char *name)
*/
bool FiosDelete(const char *name)
{
std::string filename = FiosMakeSavegameName(name);
return unlink(filename.c_str()) == 0;
return FioRemove(FiosMakeSavegameName(name));
}

typedef FiosType fios_getlist_callback_proc(SaveLoadOperation fop, const std::string &filename, const char *ext, char *title, const char *last);
Expand Down
4 changes: 2 additions & 2 deletions src/industry_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
/* Clear all input cargo types */
for (size_t j = 0; j < i->accepts_cargo.size(); j++) i->accepts_cargo[j] = INVALID_CARGO;
/* Query actual types */
uint maxcargoes = (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) ? (uint)std::size(i->accepts_cargo) : 3;
uint maxcargoes = (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) ? INDUSTRY_NUM_INPUTS : 3;
for (uint j = 0; j < maxcargoes; j++) {
uint16_t res = GetIndustryCallback(CBID_INDUSTRY_INPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
if (res == CALLBACK_FAILED || GB(res, 0, 8) == UINT8_MAX) break;
Expand Down Expand Up @@ -1948,7 +1948,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
/* Clear all output cargo types */
for (size_t j = 0; j < i->produced_cargo.size(); j++) i->produced_cargo[j] = INVALID_CARGO;
/* Query actual types */
uint maxcargoes = (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) ? (uint)std::size(i->produced_cargo) : 2;
uint maxcargoes = (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) ? INDUSTRY_NUM_OUTPUTS : 2;
for (uint j = 0; j < maxcargoes; j++) {
uint16_t res = GetIndustryCallback(CBID_INDUSTRY_OUTPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
if (res == CALLBACK_FAILED || GB(res, 0, 8) == UINT8_MAX) break;
Expand Down
8 changes: 5 additions & 3 deletions src/industry_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,14 @@ class BuildIndustryWindow : public Window {
{
switch (widget) {
case WID_DPI_MATRIX_WIDGET: {
Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES);
SetDParamMaxDigits(0, 4);
Dimension count = GetStringBoundingBox(STR_JUST_COMMA, FS_SMALL);
Dimension d{};
for (const auto &indtype : this->list) {
d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(indtype)->name));
}
resize.height = std::max<uint>(this->legend.height, GetCharacterHeight(FS_NORMAL)) + padding.height;
d.width += this->legend.width + WidgetDimensions::scaled.hsep_wide + padding.width;
resize.height = std::max<uint>({this->legend.height, d.height, count.height}) + padding.height;
d.width += this->legend.width + WidgetDimensions::scaled.hsep_wide + WidgetDimensions::scaled.hsep_normal + count.width + padding.width;
d.height = 5 * resize.height;
size = maxdim(size, d);
break;
Expand Down
Loading

0 comments on commit feeea06

Please sign in to comment.