Skip to content

Commit

Permalink
Background fill the .ico
Browse files Browse the repository at this point in the history
- Add additional ignores/msbuild deletes to icon gen script
  • Loading branch information
Cyberboss committed Sep 15, 2023
1 parent d3c8594 commit e8d83c6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ packaging/
/src/Tgstation.Server.Common/node_modules
/src/Tgstation.Server.Common/package.json
/src/Tgstation.Server.Common/yarn.lock
/src/Tgstation.Server.Common/logo_bg_white.svg
yarn-error.log*
6 changes: 5 additions & 1 deletion build/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/Tgstation.Server.Common/Tgstation.Server.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<!-- This is here because I know we have node as a build dep so this just works -->
<Target Name="IconGeneration" BeforeTargets="ResolveAssemblyReferences" Inputs="../../build/logo.svg" Outputs="../../artifacts/tgs.ico;../../artifacts/tgs.png">
<Target Name="IconGeneration" BeforeTargets="ResolveAssemblyReferences" Inputs="build_logo.js;../../build/logo.svg" Outputs="../../artifacts/tgs.ico;../../artifacts/tgs.png">
<Message Text="Restoring yarn packages..." Importance="high" />
<Exec Command="npx --yes yarn add [email protected] [email protected]" />
<Message Text="Generating icons from SVG..." Importance="high" />
Expand All @@ -24,6 +24,6 @@

<Target Name="IconNodeCleanup" AfterTargets="IconGeneration;IconClean">
<RemoveDir Directories="node_modules" />
<Delete Files="package.json;yarn.lock" />
<Delete Files="package.json;yarn.lock;logo_bg_white.svg;yarn-error.log" />
</Target>
</Project>
18 changes: 13 additions & 5 deletions src/Tgstation.Server.Common/build_logo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Prereq packages: [email protected] [email protected]
// Usage: node ./build_logo.js
// Generates ../../artifacts/tgs.ico and ../../artifacts/tgs.ico
// Generates ../../artifacts/tgs.ico and ../../artifacts/tgs.ico

const svg_to_img = require("svg-to-ico");
const svg2img = require('svg2img');
Expand All @@ -10,12 +10,19 @@ if (!fs.existsSync("../../artifacts")) {
fs.mkdirSync("../../artifacts",'0777', true);
}

const svg_bytes = fs.readFileSync("../../build/logo.svg");
const svg = svg_bytes.toString();
const white_bg_svg = svg
.replace("<!-- DO NOT CHANGE THIS LINE, UNCOMMENTING IT ENABLES THE WHITE BACKGROUND FOR THE .ICO--><!--", "")
.replace("SCRIPT_REPLACE_TOKEN", "");
fs.writeFileSync("logo_white_bg.svg", white_bg_svg);

svg_to_img({
input_name: "../../build/logo.svg",
input_name: "logo_white_bg.svg",
output_name: "../../artifacts/tgs.ico",
sizes: [ 160 ]
}).then(() => {
// this package sucks, path separators are fucked
fs.unlinkSync("logo_white_bg.svg");
svg2img(
"../../build/logo.svg",
{
Expand All @@ -35,6 +42,7 @@ svg_to_img({
fs.writeFileSync("../../artifacts/tgs.png", buffer);
});
}).catch((error) => {
console.error(`ICO conversion failed: ${error}`);
exit(1);
fs.unlinkSync("logo_white_bg.svg");
console.error(`ICO conversion failed: ${error}`);
exit(1);
});

0 comments on commit e8d83c6

Please sign in to comment.