Skip to content

Commit

Permalink
Merge pull request #12 from Sak32009/dev
Browse files Browse the repository at this point in the history
Updated third-party and libs deps + improved package_win_release.bat and build_win_premake.bat + added generate_credits.bat from SOURCE.txt files.
  • Loading branch information
Detanup01 authored Aug 18, 2024
2 parents 557aa02 + 0baf865 commit c1a3856
Show file tree
Hide file tree
Showing 34 changed files with 13,694 additions and 4,818 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Prepare release

on:
push:
tags:
tags:
- release-*
workflow_dispatch:
# allows manual trigger
Expand Down Expand Up @@ -58,12 +58,12 @@ jobs:
dir /s /b /a:-d build\win
### remove linker files
- name: Remove linker files
shell: cmd
working-directory: ${{ github.workspace }}
run: |
del /f /s /q build\win\*.exp,build\win\*.lib
exit /b 0
### - name: Remove linker files
### shell: cmd
### working-directory: ${{ github.workspace }}
### run: |
### del /f /s /q build\win\*.exp,build\win\*.lib
### exit /b 0

### package (release mode)
- name: Package build (release)
Expand Down
1,613 changes: 1,078 additions & 535 deletions CREDITS.md

Large diffs are not rendered by default.

237 changes: 117 additions & 120 deletions build_win_premake.bat
Original file line number Diff line number Diff line change
@@ -1,120 +1,117 @@
@echo off
setlocal

:: use 70%
set /a build_threads=2
if defined NUMBER_OF_PROCESSORS (
set /a build_threads=NUMBER_OF_PROCESSORS*70/100
)
if %build_threads% lss 1 (
set /a build_threads=1
)

set /a BUILD_DEPS=0
:args_loop
if "%~1"=="" (
goto :args_loop_end
) else if "%~1"=="--deps" (
set /a BUILD_DEPS=1
) else if "%~1"=="--help" (
call :help_page
goto :end_script
) else (
1>&2 echo "invalid arg %~1"
goto :end_script_with_err
)
shift /1
goto :args_loop
:args_loop_end

set "premake_exe=third-party\common\win\premake\premake5.exe"
if not exist "%premake_exe%" (
1>&2 echo "preamke wasn't found"
goto :end_script_with_err
)

:: build deps
if %BUILD_DEPS%==0 (
goto :build_deps_end
)
set "CMAKE_GENERATOR=Visual Studio 17 2022"
call "%premake_exe%" --file="premake5-deps.lua" --all-ext --all-build --64-build --32-build --verbose --clean --os=windows vs2022
if %errorlevel% neq 0 (
goto :end_script_with_err
)
:build_deps_end

:: VS WHERE to get MSBUILD
set "vswhere_exe=third-party\common\win\vswhere\vswhere.exe"
if not exist "%vswhere_exe%" (
1>&2 echo "vswhere wasn't found"
goto :end_script_with_err
)

:: .sln file
set "sln_file=build\project\vs2022\win\gbe.sln"

:: get msbuild path
set "my_vs_path="
for /f "tokens=* delims=" %%A in ('"%vswhere_exe%" -prerelease -latest -nocolor -nologo -property installationPath 2^>nul') do (
set "my_vs_path=%%~A\MSBuild\Current\Bin\MSBuild.exe"
)
if not exist "%my_vs_path%" (
1>&2 echo "MSBuild wasn't found"
goto :end_script_with_err
)

call "%premake_exe%" --file="premake5.lua" --dosstub --winrsrc --winsign --genproto --os=windows vs2022
if %errorlevel% neq 0 (
goto :end_script_with_err
)
if not exist "%sln_file%" (
1>&2 echo "project solution file wasn't found"
goto :end_script_with_err
)

:: -v:n make it so we can actually see what commands it runs
echo: & echo building debug x64
call "%my_vs_path%" /nologo "%sln_file%" /p:Configuration=debug /p:Platform=x64 -v:n -m:%build_threads%
if %errorlevel% neq 0 (
goto :end_script_with_err
)

echo: & echo building debug x32
call "%my_vs_path%" /nologo "%sln_file%" /p:Configuration=debug /p:Platform=Win32 -v:n -m:%build_threads%
if %errorlevel% neq 0 (
goto :end_script_with_err
)

echo: & echo building release x64
call "%my_vs_path%" /nologo "%sln_file%" /p:Configuration=release /p:Platform=x64 -v:n -m:%build_threads%
if %errorlevel% neq 0 (
goto :end_script_with_err
)

echo: & echo building release x32
call "%my_vs_path%" /nologo "%sln_file%" /p:Configuration=release /p:Platform=Win32 -v:n -m:%build_threads%
if %errorlevel% neq 0 (
goto :end_script_with_err
)


:: if all ok
:end_script
endlocal
exit /b 0


:: exit with error
:end_script_with_err
endlocal
exit /b 1


:help_page
echo:
echo "%~nx0" [switches]
echo switches:
echo --deps: rebuild third-party dependencies
echo --help: show this page
exit /b 0
@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0"

set /a "MAX_THREADS=2"
if defined NUMBER_OF_PROCESSORS (
:: use 70%
set /a "MAX_THREADS=%NUMBER_OF_PROCESSORS% * 70 / 100"
if %MAX_THREADS% lss 1 (
set /a "MAX_THREADS=1"
)
)

set /a "BUILD_DEPS=0"

:args_loop
if "%~1" equ "" (
goto :args_loop_end
) else if "%~1" equ "--deps" (
set /a "BUILD_DEPS=1"
) else if "%~1" equ "--help" (
goto :help_page
) else (
1>&2 echo: invalid arg %~1
goto :end_script_with_err
)

shift /1
goto :args_loop

:args_loop_end
:: check premake
set "PREMAKE_EXE=third-party\common\win\premake\premake5.exe"
if not exist "%PREMAKE_EXE%" (
1>&2 echo: premake wasn't found
goto :end_script_with_err
)

:: build deps
if %BUILD_DEPS% equ 1 (
set "CMAKE_GENERATOR=Visual Studio 17 2022"
call "%PREMAKE_EXE%" --file="premake5-deps.lua" --64-build --32-build --all-ext --all-build --j=2 --verbose --clean --os=windows vs2022
if %errorlevel% neq 0 (
goto :end_script_with_err
)
goto :end_script
)

:: check vswhere
set "VSWHERE_EXE=third-party\common\win\vswhere\vswhere.exe"
if not exist "%VSWHERE_EXE%" (
1>&2 echo: vswhere wasn't found
goto :end_script_with_err
)

:: check msbuild
set "MSBUILD_EXE="
for /f "tokens=* delims=" %%A in ('"%VSWHERE_EXE%" -prerelease -latest -nocolor -nologo -property installationPath 2^>nul') do (
set "MSBUILD_EXE=%%~A\MSBuild\Current\Bin\MSBuild.exe"
)
if not exist "%MSBUILD_EXE%" (
1>&2 echo: MSBuild wasn't found
goto :end_script_with_err
)

:: create .sln
call "%PREMAKE_EXE%" --file="premake5.lua" --genproto --dosstub --winrsrc --winsign --os=windows vs2022
if %errorlevel% neq 0 (
goto :end_script_with_err
)

:: check .sln
set "SLN_FILE=build\project\vs2022\win\gbe.sln"
if not exist "%SLN_FILE%" (
1>&2 echo: .sln file wasn't found
goto :end_script_with_err
)

:: build .sln
set "BUILD_TYPES=release debug"
set "BUILD_PLATFORMS=x64 Win32"
set "BUILD_TARGETS=api_regular api_experimental steamclient_experimental_stub steamclient_experimental steamclient_experimental_loader steamclient_experimental_extra lib_game_overlay_renderer tool_lobby_connect tool_generate_interfaces"

for %%A in (%BUILD_TYPES%) do (
set "BUILD_TYPE=%%A"
for %%B in (%BUILD_PLATFORMS%) do (
set "BUILD_PLATFORM=%%B"
for %%C in (%BUILD_TARGETS%) do (
set "BUILD_TARGET=%%C"
echo. & echo: building !BUILD_TARGET! !BUILD_TYPE! !BUILD_PLATFORM!
call "%MSBUILD_EXE%" /nologo -m:%MAX_THREADS% -v:n /p:Configuration=!BUILD_TYPE!,Platform=!BUILD_PLATFORM! /target:!BUILD_TARGET! "%SLN_FILE%"
if %errorlevel% neq 0 (
goto :end_script_with_err
)
)
)
)

goto :end_script

:: exit without error
:end_script
endlocal
exit /b 0

:: exit with error
:end_script_with_err
endlocal
exit /b 1

:: show help page
:help_page
echo: "%~nx0" [switches]
echo: switches:
echo: --deps: rebuild third-party dependencies
echo: --help: show this page
goto :end_script
3 changes: 3 additions & 0 deletions build_win_premake_deps.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

call "build_win_premake.bat" --deps
27 changes: 14 additions & 13 deletions dll/local_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define STBI_ONLY_JPEG
#if defined(__WINDOWS__)
#define STBI_WINDOWS_UTF8
#define STBIW_WINDOWS_UTF8
#endif
#include "stb/stb_image.h"

Expand All @@ -31,7 +32,7 @@
#include "stb/stb_image_write.h"

#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "stb/stb_image_resize.h"
#include "stb/stb_image_resize2.h"

struct File_Data {
std::string name{};
Expand Down Expand Up @@ -328,7 +329,7 @@ static int mkdir_p(const char *dir, const mode_t mode) {
char *p = NULL;
struct stat sb;
size_t len;

/* copy path */
len = strnlen (dir, PATH_MAX_STRING_SIZE);
if (len == 0 || len == PATH_MAX_STRING_SIZE) {
Expand All @@ -348,7 +349,7 @@ static int mkdir_p(const char *dir, const mode_t mode) {
return 0;
}
}

/* recursive mkdir */
for(p = tmp + 1; *p; p++) {
if(*p == '/') {
Expand Down Expand Up @@ -448,7 +449,7 @@ static std::vector<struct File_Data> get_filenames_recursive(std::string base_pa
}


#endif
#endif

std::string Local_Storage::get_program_path()
{
Expand All @@ -473,7 +474,7 @@ std::string Local_Storage::get_user_appdata_path()
}

#else
/* $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored.
/* $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored.
If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. */
char *datadir = getenv("XDG_DATA_HOME");
if (datadir) {
Expand All @@ -500,7 +501,7 @@ static std::string replace_with(std::string s, std::string const &old, const cha
static std::string sanitize_file_name(std::string name)
{
if (name.empty()) return name;

//I'm not sure all of these are necessary but just to be sure
if (name[0] == '.' && name.size() > 2 && (name[1] == '\\' || name[1] == '/')) name.erase(0, 2);

Expand All @@ -523,7 +524,7 @@ static std::string sanitize_file_name(std::string name)
static std::string desanitize_file_name(std::string name)
{
if (name.empty()) return name;

//I'm not sure all of these are necessary but just to be sure
name = replace_with(name, ".SLASH.", "/");
name = replace_with(name, ".B_SLASH.", "\\");
Expand Down Expand Up @@ -627,7 +628,7 @@ std::vector<std::string> Local_Storage::get_folders_path(std::string path)
}
}
} catch(...) { }

return output;
}

Expand Down Expand Up @@ -847,7 +848,7 @@ bool Local_Storage::write_json_file(std::string folder, std::string const&file,
inventory_file << std::setw(2) << json;
return true;
}

PRINT_DEBUG("Couldn't open file '%s' to write json", full_path.c_str());

reset_LastError();
Expand Down Expand Up @@ -882,23 +883,23 @@ std::string Local_Storage::load_image_resized(std::string const& image_path, std
PRINT_DEBUG("stbi_load('%s') -> %s", image_path.c_str(), (img ? "loaded" : stbi_failure_reason()));
if (img) {
std::vector<char> out_resized(resized_img_size);
stbir_resize_uint8(img, width, height, 0, (unsigned char*)&out_resized[0], resolution, resolution, 0, 4);
stbir_resize_uint8_linear(img, width, height, 0, (unsigned char*)&out_resized[0], resolution, resolution, 0, STBIR_RGBA);
resized_image = std::string((char*)&out_resized[0], out_resized.size());
stbi_image_free(img);
}
} else if (image_data.size()) {
std::vector<char> out_resized(resized_img_size);
stbir_resize_uint8((unsigned char*)image_data.c_str(), 184, 184, 0, (unsigned char*)&out_resized[0], resolution, resolution, 0, 4);
stbir_resize_uint8_linear((unsigned char*)image_data.c_str(), 184, 184, 0, (unsigned char*)&out_resized[0], resolution, resolution, 0, STBIR_RGBA);
resized_image = std::string((char*)&out_resized[0], out_resized.size());
}

reset_LastError();
return resized_image;
}

bool Local_Storage::save_screenshot(std::string const& image_path, uint8_t* img_ptr, int32_t width, int32_t height, int32_t channels)
{
std::string screenshot_path(save_directory + appid + screenshots_folder + PATH_SEPARATOR);
std::string screenshot_path(save_directory + appid + screenshots_folder + PATH_SEPARATOR);
create_directory(screenshot_path);
screenshot_path += image_path;
return stbi_write_png(screenshot_path.c_str(), width, height, channels, img_ptr, 0) == 1;
Expand Down
Loading

0 comments on commit c1a3856

Please sign in to comment.