diff --git a/.gitignore b/.gitignore index bee4ff5..2b823d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /.vscode -/*.zip +/build .DS_Store \ No newline at end of file diff --git a/mod/aa_header.rpy b/mod/aa_header.rpy index 86db073..d41f113 100644 --- a/mod/aa_header.rpy +++ b/mod/aa_header.rpy @@ -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: diff --git a/mod/autostart.rpy b/mod/autostart.rpy index 1aa10a9..c08d553 100644 --- a/mod/autostart.rpy +++ b/mod/autostart.rpy @@ -116,6 +116,7 @@ init python in masAutostart_api: if renpy.windows: import subprocess + import tempfile _PLATFORM_CURRENT = _PLATFORM_WINDOWS @@ -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) @@ -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 diff --git a/mod/platform/shortcut.vbs b/mod/platform/shortcut.vbs index a667334..1025938 100644 --- a/mod/platform/shortcut.vbs +++ b/mod/platform/shortcut.vbs @@ -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 \ No newline at end of file diff --git a/mod/topics.rpy b/mod/topics.rpy index 4014ada..176456e 100644 --- a/mod/topics.rpy +++ b/mod/topics.rpy @@ -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!" diff --git a/scripts/build.ps1 b/scripts/build.ps1 new file mode 100755 index 0000000..d07aa9d --- /dev/null +++ b/scripts/build.ps1 @@ -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 \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh index 5af17fb..c1ab34d 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -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") \ No newline at end of file +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") \ No newline at end of file