Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6f7ef36

Browse files
committed
preparing launcher improvement attempt
1 parent e8401af commit 6f7ef36

15 files changed

+327
-2
lines changed

portable/build_my_launchers.bat

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ set VCVARS_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\
77

88
rem pick the right ones and rename them in launchers_final
99
set do_launcher=%~dp0launchers_src\build_one_launcher.bat
10+
set do_launcher_original=%~dp0launchers_src_original\build_one_launcher.bat
1011

1112
::WINDOWS launchers
12-
call %do_launcher% "powershell.ico" "cmd_ps.bat" "WinPython Powershell Prompt" WINDOWS
13+
call %do_launcher% "python.ico" "winidle.bat" "IDLE (Python GUI)" WINDOWS
1314

15+
echo displace this pause if you want to re-build more
1416
pause
15-
call %do_launcher% "python.ico" "winidle.bat" "IDLE (Python GUI)" WINDOWS
17+
exit
18+
19+
20+
call %do_launcher% "powershell.ico" "cmd_ps.bat" "WinPython Powershell Prompt" WINDOWS
1621
call %do_launcher% "spyder.ico" "winspyder.bat" "Spyder" WINDOWS
1722
call %do_launcher% "spyder_reset.ico" "spyder_reset.bat" "Spyder reset" WINDOWS
1823
call %do_launcher% "code.ico" "winvscode.bat" "VS Code" WINDOWS
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
197 KB
Binary file not shown.
186 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
DataLab-WinPython license terms
2+
===============================
3+
4+
DataLab-WinPython is a Python distribution for Windows:
5+
- Based on WinPython, a portable distribution of Python for Windows (see section I. below).
6+
- Including DataLab, an open-source platform for signal and image processing (see section II. below).
7+
8+
I. - WinPython License Agreement (MIT License)
9+
----------------------------------------------
10+
11+
Copyright (c) 2012 Pierre Raybaut, 2016+ WinPython team
12+
13+
Permission is hereby granted, free of charge, to any person
14+
obtaining a copy of this software and associated documentation
15+
files (the "Software"), to deal in the Software without
16+
restriction, including without limitation the rights to use,
17+
copy, modify, merge, publish, distribute, sublicense, and/or sell
18+
copies of the Software, and to permit persons to whom the
19+
Software is furnished to do so, subject to the following
20+
conditions:
21+
22+
The above copyright notice and this permission notice shall be
23+
included in all copies or substantial portions of the Software.
24+
25+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
27+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
29+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
30+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32+
OTHER DEALINGS IN THE SOFTWARE.
33+
34+
II. - DataLab License Agreement (BSD 3-Clause License)
35+
------------------------------------------------------
36+
37+
Copyright (c) 2023, DataLab Platform Developers.
38+
All rights reserved.
39+
40+
Redistribution and use in source and binary forms, with or without
41+
modification, are permitted provided that the following conditions are met:
42+
43+
1. Redistributions of source code must retain the above copyright notice, this
44+
list of conditions and the following disclaimer.
45+
46+
2. Redistributions in binary form must reproduce the above copyright notice,
47+
this list of conditions and the following disclaimer in the documentation
48+
and/or other materials provided with the distribution.
49+
50+
3. Neither the name of the copyright holder nor the names of its
51+
contributors may be used to endorse or promote products derived from
52+
this software without specific prior written permission.
53+
54+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
55+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
57+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
58+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
60+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
61+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
62+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
63+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
@echo on
2+
set icon_name=%1
3+
set LAUNCH_TARGET=%2
4+
set launcher_name=%3
5+
set subsystem=%4
6+
7+
set icon_name=%icon_name:"=%
8+
set LAUNCH_TARGET=%LAUNCH_TARGET:"=%
9+
set launcher_name=%launcher_name:"=%
10+
set subsystem=%subsystem:"=%
11+
12+
set ROOT_PATH=%~dp0..\
13+
set SCRIPT_PATH=%~dp0
14+
set TEMPO_PATH=%ROOT_PATH%launchers_temp
15+
set OUTPUT_DIR=%ROOT_PATH%launchers_final
16+
17+
set "ICON_FILE=%ROOT_PATH%icons\%icon_name%"
18+
set LAUNCHER_EXE=%OUTPUT_DIR%\%launcher_name%.exe
19+
20+
21+
:: Paths to template WINDOWS or CONSOLE
22+
set SOURCE_FILE=%SCRIPT_PATH%launcher_template_%subsystem%.cpp
23+
echo SOURCE_FILE=%SOURCE_FILE%
24+
25+
set "RESOURCE_FILE=%TEMPO_PATH%\%icon_name%.rc"
26+
set "RESOURCE_OBJ=%TEMPO_PATH%\%icon_name%.res"
27+
28+
29+
:: create pDirectory if needed
30+
if not exist "%OUTPUT_DIR%" mkdir "%OUTPUT_DIR%"
31+
if not exist "%TEMPO_PATH%" mkdir "%TEMPO_PATH%"
32+
33+
cd/d %TEMPO_PATH%
34+
35+
:: Check if MSVC environment is already initialized
36+
if not defined VSINSTALLDIR (
37+
echo Initializing MSVC environment...
38+
call %VCVARS_PATH%
39+
if errorlevel 1 (
40+
echo [ERROR] Failed to initialize MSVC environment.
41+
exit /b 1
42+
)
43+
)
44+
45+
@echo on
46+
47+
:: Walk through .bat files in the current directory
48+
echo Processing %icon_name%..
49+
:: Stonebig: Remove previous .exe file
50+
echo launcher_exe_action del /q "%LAUNCHER_EXE%"
51+
if exist "%LAUNCHER_EXE%" (
52+
move "%LAUNCHER_EXE%" "%LAUNCHER_EXE%.old.exe"
53+
del /q "%LAUNCHER_EXE%.old.exe"
54+
)
55+
:: Stonebig: Remove intermediate .res and.rc file
56+
if exist "%RESOURCE_OBJ%" (
57+
move "%RESOURCE_OBJ%" "%RESOURCE_OBJ%.old.exe"
58+
del /q "%RESOURCE_OBJ%.old.exe"
59+
)
60+
if exist "%RESOURCE_FILE%" (
61+
move "%RESOURCE_FILE%" "%RESOURCE_FILE%.old.exe"
62+
del /q "%RESOURCE_FILE%.old.exe"
63+
)
64+
:: Remove intermediate .obj file
65+
del /q "launcher_template_%subsystem%.obj"
66+
67+
:: Check if the icon exists
68+
if exist "%ICON_FILE%" (
69+
echo Icon found: "%ICON_FILE%"
70+
) else (
71+
echo No icon found for "%ICON_FILE%" stoping
72+
pause
73+
exit
74+
)
75+
76+
77+
:: Create resource file
78+
echo Creating resource file...
79+
> "%RESOURCE_FILE%" echo IDI_ICON1 ICON "%ICON_FILE%"
80+
:: Compile resource
81+
echo Compiling resource...
82+
rc /fo "%RESOURCE_OBJ%" "%RESOURCE_FILE%"
83+
84+
:: Compile the launcher executable
85+
echo Compiling launcher executable...
86+
cl /EHsc /O2 /DUNICODE /W4 "%SOURCE_FILE%" "%RESOURCE_OBJ%" ^
87+
/Fe"%LAUNCHER_EXE%%" ^
88+
/DLAUNCH_TARGET=\"%LAUNCH_TARGET%\" ^
89+
User32.lib ^
90+
/link /SUBSYSTEM:%subsystem%
91+
92+
93+
if errorlevel 1 (
94+
echo [ERROR] Failed to build launcher for %LAUNCH_TARGET%
95+
exit /b 1
96+
)
97+
98+
if exist "%LAUNCHER_EXE%" (
99+
echo [SUCCESS] Launcher created: "%LAUNCHER_EXE%""
100+
) else (
101+
echo [ERROR] Failed to build launcher "%LAUNCHER_EXE%" from "%icon_name%" to call "%LAUNCH_TARGET%"
102+
exit /b 1
103+
)
104+
105+
echo All launchers processed.
106+
rem exit /b 0
107+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
DataLab-WinPython launcher script
3+
---------------------------------
4+
5+
Licensed under the terms of the BSD 3-Clause
6+
(see ./LICENSE for details)
7+
8+
*/
9+
10+
#include <windows.h>
11+
#include <string>
12+
13+
int main() {
14+
// Get the path to the current executable
15+
wchar_t exePath[MAX_PATH];
16+
GetModuleFileNameW(NULL, exePath, MAX_PATH);
17+
18+
// Determine the directory of the executable
19+
std::wstring exeDir = exePath;
20+
exeDir = exeDir.substr(0, exeDir.find_last_of(L"\\/"));
21+
22+
// Define the path to the "scripts" directory
23+
std::wstring scriptsDir = exeDir + L"\\scripts";
24+
25+
// Check if the "scripts" directory exists
26+
DWORD attributes = GetFileAttributesW(scriptsDir.c_str());
27+
if (attributes == INVALID_FILE_ATTRIBUTES || !(attributes & FILE_ATTRIBUTE_DIRECTORY)) {
28+
MessageBoxW(NULL, L"The 'scripts' directory does not exist. Please ensure it is in the same folder as the launcher.",
29+
L"Launcher Error", MB_ICONERROR);
30+
return 1;
31+
}
32+
33+
// Set the working directory to the "scripts" folder
34+
if (!SetCurrentDirectoryW(scriptsDir.c_str())) {
35+
MessageBoxW(NULL, L"Failed to set the working directory to 'scripts'.",
36+
L"Launcher Error", MB_ICONERROR);
37+
return 1;
38+
}
39+
40+
// Define the command to run
41+
std::wstring target = L"cmd.exe /c \"" LAUNCH_TARGET L"\"";
42+
43+
// Configure the process startup info
44+
STARTUPINFO si = { sizeof(si) };
45+
si.dwFlags = STARTF_USESHOWWINDOW; // Prevent the window from appearing
46+
si.wShowWindow = SW_HIDE; // Hide the command window
47+
48+
PROCESS_INFORMATION pi = {};
49+
50+
// Start the process without CREATE_NO_WINDOW flag to show the command window
51+
if (!CreateProcessW(
52+
NULL, // Application name (NULL because we pass the command in the command line)
53+
&target[0], // Command line
54+
NULL, // Process security attributes
55+
NULL, // Thread security attributes
56+
FALSE, // Inherit handles
57+
0, // No special flags
58+
NULL, // Environment block (NULL to inherit parent)
59+
NULL, // Current directory (NULL to use the parent process's current directory)
60+
&si, // Startup info
61+
&pi // Process information
62+
)) {
63+
MessageBoxW(NULL, L"Failed to launch the script.", L"Launcher Error", MB_ICONERROR);
64+
return 1;
65+
}
66+
67+
// Wait for the script to finish
68+
WaitForSingleObject(pi.hProcess, INFINITE);
69+
70+
// Cleanup
71+
CloseHandle(pi.hProcess);
72+
CloseHandle(pi.hThread);
73+
74+
return 0;
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
DataLab-WinPython launcher script
3+
---------------------------------
4+
5+
Licensed under the terms of the BSD 3-Clause
6+
(see ./LICENSE for details)
7+
8+
*/
9+
10+
#include <windows.h>
11+
#include <string>
12+
13+
int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/) {
14+
// Get the path to the current executable
15+
wchar_t exePath[MAX_PATH];
16+
GetModuleFileNameW(NULL, exePath, MAX_PATH);
17+
18+
// Determine the directory of the executable
19+
std::wstring exeDir = exePath;
20+
exeDir = exeDir.substr(0, exeDir.find_last_of(L"\\/"));
21+
22+
// Define the path to the "scripts" directory
23+
std::wstring scriptsDir = exeDir + L"\\scripts";
24+
25+
// Check if the "scripts" directory exists
26+
DWORD attributes = GetFileAttributesW(scriptsDir.c_str());
27+
if (attributes == INVALID_FILE_ATTRIBUTES || !(attributes & FILE_ATTRIBUTE_DIRECTORY)) {
28+
MessageBoxW(NULL, L"The 'scripts' directory does not exist. Please ensure it is in the same folder as the launcher.",
29+
L"Launcher Error", MB_ICONERROR);
30+
return 1;
31+
}
32+
33+
// Set the working directory to the "scripts" folder
34+
if (!SetCurrentDirectoryW(scriptsDir.c_str())) {
35+
MessageBoxW(NULL, L"Failed to set the working directory to 'scripts'.",
36+
L"Launcher Error", MB_ICONERROR);
37+
return 1;
38+
}
39+
40+
// Define the command to run
41+
std::wstring target = L"cmd.exe /c \"" LAUNCH_TARGET L"\"";
42+
43+
// Configure the process startup info
44+
STARTUPINFO si = { sizeof(si) };
45+
si.dwFlags = STARTF_USESHOWWINDOW; // Prevent the window from appearing
46+
si.wShowWindow = SW_HIDE; // Hide the command window
47+
48+
PROCESS_INFORMATION pi = {};
49+
50+
// Start the process with CREATE_NO_WINDOW flag
51+
if (!CreateProcessW(
52+
NULL, // Application name (NULL because we pass the command in the command line)
53+
&target[0], // Command line
54+
NULL, // Process security attributes
55+
NULL, // Thread security attributes
56+
FALSE, // Inherit handles
57+
CREATE_NO_WINDOW, // Flags to prevent creating a window
58+
NULL, // Environment block (NULL to inherit parent)
59+
NULL, // Current directory (NULL to use the parent process's current directory)
60+
&si, // Startup info
61+
&pi // Process information
62+
)) {
63+
MessageBoxW(NULL, L"Failed to launch the script.", L"Launcher Error", MB_ICONERROR);
64+
return 1;
65+
}
66+
67+
// Wait for the script to finish
68+
WaitForSingleObject(pi.hProcess, INFINITE);
69+
70+
// Cleanup
71+
CloseHandle(pi.hProcess);
72+
CloseHandle(pi.hThread);
73+
74+
return 0;
75+
}

0 commit comments

Comments
 (0)