Skip to content

Commit

Permalink
Merge pull request #8 from Friends-of-Monika/dev
Browse files Browse the repository at this point in the history
Release 1.1.8
  • Loading branch information
dreamscached authored Oct 6, 2022
2 parents 4280477 + 6ffc8ed commit 9e95f11
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/.vscode
/*.zip
/build
.DS_Store
2 changes: 1 addition & 1 deletion mod/aa_header.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ init -990 python in mas_submod_utils:
name="MAS Autostart Mod",
description="Let your Monika auto-start the game for you as soon as "
"your computer boots up!",
version="1.1.7"
version="1.1.8"
)

init -989 python:
Expand Down
35 changes: 27 additions & 8 deletions mod/autostart.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ init python in masAutostart_api:

if renpy.windows:
import subprocess
import tempfile


_PLATFORM_CURRENT = _PLATFORM_WINDOWS
Expand Down Expand Up @@ -321,9 +322,10 @@ init python in masAutostart_api:
"""

param = (
"cscript", # VBScript interpreter command
"wscript", # VBScript interpreter command
"/nologo", # Exclude Microsoft banner
_AUTOSTART_SHORTCUT_SCRIPT, # shortcut.vbs path
"create", # "create" subcommand
_DEFAULT_AUTOSTART_FILE, # Path to autostart shortcut
_LAUNCHER_PATH, # Path to launcher executable
os.path.dirname(_LAUNCHER_PATH) # Working dir (DDLC folder)
Expand Down Expand Up @@ -665,24 +667,41 @@ init python in masAutostart_api:
if not path.lower().endswith(".lnk"):
return False

out_file = tempfile.mktemp()

try:
param = (
"cscript", # VBScript interpreter command
"wscript", # VBScript interpreter command
"/nologo", # Exclude Microsoft banner
_AUTOSTART_SHORTCUT_SCRIPT, # shortcut.vbs path
"check", # "check" subcommand
out_file, # File to write output to
path # Path to autostart shortcut
)

target_path = subprocess.check_output(param)
subprocess.check_output(param)
target_path = __map_file(out_file, "r", lambda f: f.read())

try:
os.remove(out_file)
except IOError as e:
pass

if target_path.strip() != _LAUNCHER_PATH:
return False

except subprocess.CalledProcessError as e:
log.error(
"Could not check shortcut " + path + "; "
"shortcut script returned non-zero exit code " + str(e.returncode)
)
except (subprocess.CalledProcessError, IOError) as e:
if isinstance(e, subprocess.CalledProcessError):
log.error(
"Could not check shortcut " + path + "; "
"shortcut script returned non-zero exit code " + str(e.returncode)
)
else:
log.error(
"Could not check shortcut " + path + "; "
"could not read from output file: " + str(e)
)

log.debug("shortcut.vbs was called with parameters: {0}.".format(param))
return False

Expand Down
37 changes: 25 additions & 12 deletions mod/platform/shortcut.vbs
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
' This is Windows-specific VBScript file used for creating or checking shortcut
' in autostart folder without a need to add winshell/pywin32 dependencies.
' The script must be invoked with three positional parameters:
' 0: shortcut path (must contain filename ending with .lnk)
' 1: target executable path
' 2: executable working directory
' If only one positional parameter is passed (shortcut path), its target
' is written to standard output stream.
' The script must be invoked with the following parameters:
' For shortcut creation:
' 0: constant value of "create", a subcommand
' 1: shortcut path (must contain filename ending with .lnk)
' 2: target executable path
' 3: executable working directory
' For shortcut path checking:
' 0: constant value of "check", a subcommand
' 1: file to write output to
' 2: path to check shortcut path of

' Adopted and reworked from https://superuser.com/a/392082.
' Huge thanks to original answer author for saving us lots of time
' we could instead waste on messing with winshell/pywin32.

Set Shell = WScript.CreateObject("WScript.Shell")
Set Shortcut = Shell.CreateShortcut(WScript.Arguments(0))

If WScript.Arguments.Length = 3 Then
Shortcut.TargetPath = WScript.Arguments(1)
Shortcut.WorkingDirectory = WScript.Arguments(2)
If WScript.Arguments(0) = "create" Then
' Create a shortcut object for parameter 1 with target path as parameter 2
' and working directory as parameter 3.
Set Shortcut = Shell.CreateShortcut(WScript.Arguments(1))
Shortcut.TargetPath = WScript.Arguments(2)
Shortcut.WorkingDirectory = WScript.Arguments(3)
Shortcut.Save

Else
WScript.Echo Shortcut.TargetPath
ElseIf WScript.Arguments(0) = "check" Then
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Const MODE_WRITE = 2

' Open output file for parameter 1 for writing to write shortcut for
' parameter 2 target path to.
Set OutputStream = FileSystem.CreateTextFile(WScript.Arguments(1), MODE_WRITE)
Set Shortcut = Shell.CreateShortcut(WScript.Arguments(2))
OutputStream.WriteLine(Shortcut.TargetPath)

End If
3 changes: 0 additions & 3 deletions mod/topics.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ label masAutostart_req_enable:
m 1eub "Sure, [mas_get_player_nickname()]!~"
m 1dua "Give me a moment..."

if renpy.windows:
m 2rusdrb "A little window will open and close quickly, but don't mind it."

m 1dua "{w=0.3}.{w=0.3}.{w=0.3}.{nw}"
if store.masAutostart_api.enable():
m 1eub "Done!"
Expand Down
26 changes: 26 additions & 0 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/pwsh

function New-TemporaryDirectory {
$parent = [System.IO.Path]::GetTempPath()
$name = [System.IO.Path]::GetRandomFileName()
New-Item -ItemType Directory -Path (Join-Path $parent $name)
}

$Dir = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Definition)
$Temp = New-TemporaryDirectory

$Build = "$Dir\build"
New-Item -ItemType Directory -Force -Path $Build | Out-Null

$Name = Get-Content $Dir\mod\aa_header.rpy | Select-String '^\s*name="([^"]+)"' | ForEach-Object { $_.Matches[0].Groups[1].Value }
$Version = Get-Content $Dir\mod\aa_header.rpy | Select-String '^\s*version="([^"]+)"' | ForEach-Object { $_.Matches[0].Groups[1].Value }
$Package = $Name.ToLower() -Replace "\s", "-"

$Mod = "$Temp\game\Submods"
New-Item -ItemType Directory -Force -Path $Mod | Out-Null
$Mod = "$Mod\$Name"

Copy-Item -Recurse $Dir\mod $Mod

Compress-Archive -Update -Path $Temp\game -DestinationPath $Build\$Package-$Version.zip
Remove-Item -Recurse $Temp
19 changes: 13 additions & 6 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#!/bin/sh

# Builds a package with the submod.
# Usage: $ scripts/build PACKAGE_NAME

dir="$(dirname "$(CDPATH="" cd -- "$(dirname -- "$0")" && pwd)")"
temp="$(mktemp -d)"

mkdir -p "$temp/game/Submods"
cp -r "$dir/mod" "$temp/game/Submods/MAS Autostart Mod"
(cd "$temp" || exit 1; find game | zip -9@ "$dir/$1" && rm -rf "$temp")
build="$dir/build"
mkdir -p "$build"

name="$(perl -ne 'if (/^.*name="([^"]*)"/) { print $1; exit }' "$dir/mod/aa_header.rpy")"
version="$(perl -ne 'if (/^.*version="([^"]*)"/) { print $1; exit }' "$dir/mod/aa_header.rpy")"
package="$(echo "$name" | tr "[:upper:]" "[:lower:]" | tr "[:blank:]" "-")"

mod="$temp/game/Submods/$name"
mkdir -p "$mod"

cp -r "$dir/mod"/* "$mod"

(cd "$temp" || exit 1; find game | zip -9@q "$build/$package-$version.zip" && rm -rf "$temp")

0 comments on commit 9e95f11

Please sign in to comment.