Skip to content

Commit c8a9cd8

Browse files
author
skywind3000
committed
try to load _pystand_static.int as startup script if it exists
1 parent 84b59ff commit c8a9cd8

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

PyStand.cpp

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
// PyStand.cpp -
44
//
55
// Created by skywind on 2022/02/03
6-
// Last Modified: 2022/03/13 00:26
6+
// Last Modified: 2023/03/17 20:06
77
//
88
//=====================================================================
99
#ifdef _MSC_VER
1010
#define _CRT_SECURE_NO_WARNINGS 1
1111
#endif
1212

13-
#include "PyStand.h"
1413
#include <shlwapi.h>
1514
#include <string>
1615
#include <string.h>
1716
#include <winbase.h>
1817
#include <wincon.h>
1918

19+
#include "PyStand.h"
20+
2021
#ifdef _MSC_VER
2122
#pragma comment(lib, "shlwapi.lib")
2223
#endif
@@ -256,6 +257,15 @@ int PyStand::RunString(const char *script)
256257
}
257258

258259

260+
261+
//---------------------------------------------------------------------
262+
// static init script
263+
//---------------------------------------------------------------------
264+
#ifndef PYSTAND_STATIC_NAME
265+
#define PYSTAND_STATIC_NAME "_pystand_static.int"
266+
#endif
267+
268+
259269
//---------------------------------------------------------------------
260270
// LoadScript()
261271
//---------------------------------------------------------------------
@@ -270,25 +280,34 @@ int PyStand::DetectScript()
270280
std::wstring main = _pystand.substr(0, size);
271281
std::vector<const wchar_t*> exts;
272282
std::vector<std::wstring> scripts;
273-
exts.push_back(L".int");
274-
exts.push_back(L".py");
275-
exts.push_back(L".pyw");
276-
_script = L"";
277-
for (int i = 0; i < (int)exts.size(); i++) {
278-
std::wstring test = main + exts[i];
279-
scripts.push_back(test);
280-
if (PathFileExistsW(test.c_str())) {
281-
_script = test;
282-
break;
283-
}
283+
_script.clear();
284+
#if !(PYSTAND_DISABLE_STATIC)
285+
std::wstring test;
286+
test = _home + L"\\" + Ansi2Unicode(PYSTAND_STATIC_NAME);
287+
if (PathFileExistsW(test.c_str())) {
288+
_script = test;
284289
}
285-
if (_script.size() == 0) {
286-
std::wstring msg = L"Can't find either of:\r\n";
287-
for (int j = 0; j < (int)scripts.size(); j++) {
288-
msg += scripts[j] + L"\r\n";
290+
#endif
291+
if (_script.empty()) {
292+
exts.push_back(L".int");
293+
exts.push_back(L".py");
294+
exts.push_back(L".pyw");
295+
for (int i = 0; i < (int)exts.size(); i++) {
296+
std::wstring test = main + exts[i];
297+
scripts.push_back(test);
298+
if (PathFileExistsW(test.c_str())) {
299+
_script = test;
300+
break;
301+
}
302+
}
303+
if (_script.size() == 0) {
304+
std::wstring msg = L"Can't find either of:\r\n";
305+
for (int j = 0; j < (int)scripts.size(); j++) {
306+
msg += scripts[j] + L"\r\n";
307+
}
308+
MessageBoxW(NULL, msg.c_str(), L"ERROR", MB_OK);
309+
return -1;
289310
}
290-
MessageBoxW(NULL, msg.c_str(), L"ERROR", MB_OK);
291-
return -1;
292311
}
293312
SetEnvironmentVariableW(L"PYSTAND_SCRIPT", _script.c_str());
294313
return 0;

0 commit comments

Comments
 (0)