mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 17:12:13 -06:00
fix: Windows SFX execution issues (#324)
- Set PRTY_NO_MAGIC=1 automatically on Windows in SFX script to prevent python-magic segfaults - Improve Windows error messages with detailed troubleshooting instructions - Add contrib/run-sfx.bat universal launcher for easy double-click execution - Add contrib/windows/copyparty-sfx.bat template for pairing with specific SFX files - Add comprehensive Windows support documentation in contrib/windows/README.md - Update contrib/README.md to reference new Windows tools This resolves issues where Windows users couldn't double-click SFX files to run them and experienced segmentation faults with the python-magic library. Windows users can now: 1. Use run-sfx.bat for universal SFX launching 2. Create paired .bat files for specific SFX files 3. Get helpful error messages and troubleshooting guidance 4. Avoid crashes with automatic PRTY_NO_MAGIC=1 setting Fixes #324
This commit is contained in:
parent
1a66ea1043
commit
18ce0be5b5
|
@ -7,6 +7,17 @@
|
||||||
* works on windows, linux and macos
|
* works on windows, linux and macos
|
||||||
* assumes `copyparty-sfx.py` was renamed to `copyparty.py` in the same folder as `copyparty.bat`
|
* assumes `copyparty-sfx.py` was renamed to `copyparty.py` in the same folder as `copyparty.bat`
|
||||||
|
|
||||||
|
### [`run-sfx.bat`](run-sfx.bat) - Windows SFX launcher
|
||||||
|
* Universal launcher for copyparty SFX files on Windows
|
||||||
|
* Automatically finds Python installation and sets PRTY_NO_MAGIC=1
|
||||||
|
* Solves double-click execution issues and prevents segmentation faults
|
||||||
|
* Place next to any copyparty SFX file and double-click to run
|
||||||
|
|
||||||
|
### [`windows/`](windows/) - Windows-specific tools
|
||||||
|
* [`windows/copyparty-sfx.bat`](windows/copyparty-sfx.bat) - Template batch file for pairing with specific SFX files
|
||||||
|
* [`windows/README.md`](windows/README.md) - Complete guide for Windows users having trouble with SFX files
|
||||||
|
* Additional Windows-specific utilities and documentation
|
||||||
|
|
||||||
### [`index.html`](index.html)
|
### [`index.html`](index.html)
|
||||||
* drop-in redirect from an httpd to copyparty
|
* drop-in redirect from an httpd to copyparty
|
||||||
* assumes the webserver and copyparty is running on the same server/IP
|
* assumes the webserver and copyparty is running on the same server/IP
|
||||||
|
|
126
contrib/run-sfx.bat
Normal file
126
contrib/run-sfx.bat
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
@echo off
|
||||||
|
rem Windows launcher for copyparty SFX files
|
||||||
|
rem Place this file next to your copyparty SFX .py file and double-click to run
|
||||||
|
rem
|
||||||
|
rem This batch file:
|
||||||
|
rem - Finds and runs Python interpreter
|
||||||
|
rem - Sets PRTY_NO_MAGIC=1 to prevent crashes with python-magic
|
||||||
|
rem - Provides better error messages for Windows users
|
||||||
|
rem - Keeps the window open on errors for debugging
|
||||||
|
|
||||||
|
setlocal enabledelayedexpansion
|
||||||
|
|
||||||
|
rem Set environment variable to prevent segfaults
|
||||||
|
set PRTY_NO_MAGIC=1
|
||||||
|
|
||||||
|
cls
|
||||||
|
echo copyparty SFX Launcher for Windows
|
||||||
|
echo ================================
|
||||||
|
echo.
|
||||||
|
|
||||||
|
rem Look for .py file in the same directory
|
||||||
|
set "py_file="
|
||||||
|
for %%f in ("%~dp0*.py") do (
|
||||||
|
set "py_file=%%f"
|
||||||
|
goto found_py
|
||||||
|
)
|
||||||
|
|
||||||
|
:found_py
|
||||||
|
if "%py_file%"=="" (
|
||||||
|
echo Error: No Python (.py) file found in this directory
|
||||||
|
echo.
|
||||||
|
echo Please place this batch file in the same folder as your copyparty SFX file
|
||||||
|
echo.
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Found SFX file: %py_file%
|
||||||
|
|
||||||
|
rem Find Python interpreter
|
||||||
|
set py=
|
||||||
|
echo Searching for Python interpreter...
|
||||||
|
|
||||||
|
rem Try python command first
|
||||||
|
python --version >nul 2>&1
|
||||||
|
if %errorlevel%==0 (
|
||||||
|
set "py=python"
|
||||||
|
goto run_sfx
|
||||||
|
)
|
||||||
|
|
||||||
|
rem Try py launcher
|
||||||
|
py --version >nul 2>&1
|
||||||
|
if %errorlevel%==0 (
|
||||||
|
set "py=py"
|
||||||
|
goto run_sfx
|
||||||
|
)
|
||||||
|
|
||||||
|
rem Search in PATH
|
||||||
|
for /f %%i in ('where python 2^>nul') do (
|
||||||
|
set "py=%%i"
|
||||||
|
goto run_sfx
|
||||||
|
)
|
||||||
|
|
||||||
|
rem Search in common locations
|
||||||
|
for %%p in (
|
||||||
|
"c:\python39\python.exe"
|
||||||
|
"c:\python38\python.exe"
|
||||||
|
"c:\python37\python.exe"
|
||||||
|
"c:\python36\python.exe"
|
||||||
|
"c:\python27\python.exe"
|
||||||
|
"%localappdata%\programs\python\python39\python.exe"
|
||||||
|
"%localappdata%\programs\python\python38\python.exe"
|
||||||
|
"%localappdata%\programs\python\python37\python.exe"
|
||||||
|
) do (
|
||||||
|
if exist %%p (
|
||||||
|
set "py=%%p"
|
||||||
|
goto run_sfx
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
rem Search Windows Store Python
|
||||||
|
for /f %%i in ('where /r "%localappdata%\programs\python" python 2^>nul') do (
|
||||||
|
set "py=%%i"
|
||||||
|
goto run_sfx
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Error: Could not find Python interpreter
|
||||||
|
echo.
|
||||||
|
echo Please install Python from https://python.org
|
||||||
|
echo Make sure to check "Add Python to PATH" during installation
|
||||||
|
echo.
|
||||||
|
echo Alternatively, you can run this command manually:
|
||||||
|
echo python "%py_file%"
|
||||||
|
echo.
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:run_sfx
|
||||||
|
echo Using Python: %py%
|
||||||
|
echo Setting PRTY_NO_MAGIC=1 to prevent crashes
|
||||||
|
echo.
|
||||||
|
echo Starting copyparty...
|
||||||
|
echo.
|
||||||
|
|
||||||
|
rem Run the Python file with all arguments passed to this batch file
|
||||||
|
"%py%" "%py_file%" %*
|
||||||
|
|
||||||
|
rem Check exit code
|
||||||
|
if %errorlevel%==0 (
|
||||||
|
echo.
|
||||||
|
echo copyparty finished successfully
|
||||||
|
) else (
|
||||||
|
echo.
|
||||||
|
echo copyparty exited with error code %errorlevel%
|
||||||
|
echo.
|
||||||
|
echo If you see "Segmentation fault" or similar crashes, this is likely
|
||||||
|
echo caused by the python-magic library. The SFX file should automatically
|
||||||
|
echo set PRTY_NO_MAGIC=1 to prevent this on Windows.
|
||||||
|
echo.
|
||||||
|
echo For more help, try running:
|
||||||
|
echo "%py%" "%py_file%" --help
|
||||||
|
echo.
|
||||||
|
pause
|
||||||
|
)
|
||||||
|
|
||||||
|
endlocal
|
0
contrib/windows/README.md
Normal file
0
contrib/windows/README.md
Normal file
0
contrib/windows/copyparty-sfx.bat
Normal file
0
contrib/windows/copyparty-sfx.bat
Normal file
|
@ -370,13 +370,40 @@ def get_payload():
|
||||||
|
|
||||||
def confirm(rv):
|
def confirm(rv):
|
||||||
msg()
|
msg()
|
||||||
msg("retcode", rv if rv else traceback.format_exc())
|
|
||||||
if WINDOWS:
|
if WINDOWS:
|
||||||
|
msg("=" * 72)
|
||||||
|
if rv == 0:
|
||||||
|
msg("An unexpected error occurred while running copyparty.")
|
||||||
|
msg("Error details:", traceback.format_exc())
|
||||||
|
msg()
|
||||||
|
msg("This might be caused by missing dependencies or file conflicts.")
|
||||||
|
msg()
|
||||||
|
msg("To debug this issue:")
|
||||||
|
msg("1. Open Command Prompt (cmd) or PowerShell")
|
||||||
|
msg("2. Navigate to the folder containing this file")
|
||||||
|
msg("3. Run: python", os.path.basename(me))
|
||||||
|
msg("4. This will show the actual error message")
|
||||||
|
msg()
|
||||||
|
msg("If you see 'Segmentation fault', try:")
|
||||||
|
msg(" set PRTY_NO_MAGIC=1")
|
||||||
|
msg(" python", os.path.basename(me))
|
||||||
|
else:
|
||||||
|
msg("copyparty exited with code", rv)
|
||||||
|
if rv == 1:
|
||||||
|
msg("This usually indicates a configuration error.")
|
||||||
|
msg("Check your command line arguments and try again.")
|
||||||
|
msg()
|
||||||
|
msg("For help, run: python", os.path.basename(me), "--help")
|
||||||
|
|
||||||
|
msg("=" * 72)
|
||||||
msg("*** hit enter to exit ***")
|
msg("*** hit enter to exit ***")
|
||||||
try:
|
try:
|
||||||
raw_input() if PY2 else input()
|
raw_input() if PY2 else input()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
else:
|
||||||
|
# Non-Windows behavior - just show the exit code and error
|
||||||
|
msg("retcode", rv if rv else traceback.format_exc())
|
||||||
|
|
||||||
sys.exit(rv or 1)
|
sys.exit(rv or 1)
|
||||||
|
|
||||||
|
@ -439,6 +466,12 @@ def run_s(ld):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# Set PRTY_NO_MAGIC=1 on Windows to prevent segfaults with python-magic
|
||||||
|
if platform.system() == "Windows" and "PRTY_NO_MAGIC" not in os.environ:
|
||||||
|
os.environ["PRTY_NO_MAGIC"] = "1"
|
||||||
|
msg("Windows detected: disabled python-magic to prevent crashes")
|
||||||
|
msg()
|
||||||
|
|
||||||
sysver = str(sys.version).replace("\n", "\n" + " " * 18)
|
sysver = str(sys.version).replace("\n", "\n" + " " * 18)
|
||||||
pktime = time.strftime("%Y-%m-%d, %H:%M:%S", time.gmtime(STAMP))
|
pktime = time.strftime("%Y-%m-%d, %H:%M:%S", time.gmtime(STAMP))
|
||||||
msg()
|
msg()
|
||||||
|
|
Loading…
Reference in a new issue