autoload lua script if filename matches - ID: 3558045

added option for to autoload lua scripts when loading a rom. 
Config->Path Settings->Auto-load Lua scripts with ROM

Windows/English
This commit is contained in:
hi-coder 2012-08-16 23:38:24 +00:00
parent 874b469cf0
commit df04471b41
4 changed files with 35 additions and 0 deletions

View File

@ -412,6 +412,7 @@ extern bool allowBackgroundInput;
std::vector<HWND> LuaScriptHWnds;
LRESULT CALLBACK LuaScriptProc(HWND, UINT, WPARAM, LPARAM);
bool autoLoadLua;
#define MAX_RECENT_SCRIPTS 15 // must match value in luaconsole.cpp (belongs in a header, but I didn't want to create one just for this)
extern char Recent_Scripts[MAX_RECENT_SCRIPTS][1024];
@ -2653,6 +2654,7 @@ int _main()
GetPrivateProfileString("Watches", str, "", &rw_recent_files[i][0], 1024, IniName);
}
autoLoadLua = GetPrivateProfileBool("Scripting", "AutoLoad", false, IniName);
for(int i = 0; i < MAX_RECENT_SCRIPTS; i++)
{
@ -3466,6 +3468,30 @@ static BOOL OpenCore(const char* filename)
start_paused = 0;
}
if(autoLoadLua)
{
string luaScript;
luaScript.append(path.pathToLua);
if(!Path::IsPathRooted(luaScript))
{
luaScript.clear();
luaScript.append(path.pathToModule);
luaScript.append(path.pathToLua);
}
luaScript.append("\\");
luaScript.append(path.GetRomNameWithoutExtension());
luaScript.append(".lua");
FILE* file;
file = fopen(luaScript.c_str(), "rb");
if(file)
{
fclose(file);
HWND hDlg = CreateDialogW(hAppInst, MAKEINTRESOURCEW(IDD_LUA), MainWindow->getHWnd(), (DLGPROC) LuaScriptProc);
SendDlgItemMessage(hDlg, IDC_EDIT_LUAPATH, WM_SETTEXT, (WPARAM) 512, (LPARAM) luaScript.c_str());
}
}
// Update the toolbar
MainWindowToolbar->EnableButton(IDM_PAUSE, true);
MainWindowToolbar->EnableButton(IDM_CLOSEROM, true);

View File

@ -28,6 +28,8 @@
#include "path.h"
#include "pathsettings.h"
extern bool autoLoadLua;
#define HANDLE_DLGMSG(hwnd, message, fn) \
case (message): return (SetDlgMsgResult(hDlg, uMsg, \
HANDLE_##message( (hwnd), (wParam), (lParam), (fn) ) ) )
@ -119,6 +121,8 @@ void WritePathSettings()
WritePrivateProfileInt(SECTION, LASTVISITKEY, path.savelastromvisit, IniName);
WritePrivateProfileInt(SECTION, ASSOCIATEKEY, associate, IniName);
WritePrivateProfileBool("Scripting", "AutoLoad", autoLoadLua, IniName);
// WritePrivateProfileInt(SECTION, DEFAULTFORMATKEY, defaultFormat, IniName);
// WritePrivateProfileInt(SECTION, NEEDSSAVINGKEY, needsSaving, IniName);
}
@ -142,6 +146,7 @@ BOOL PathSettings_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam)
CheckDlgButton(hDlg, IDC_USELASTVISIT, (path.savelastromvisit) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hDlg, IDC_ASSOCIATE, (associate) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hDlg, IDC_AUTOLOADLUA, (autoLoadLua) ? BST_CHECKED : BST_UNCHECKED);
CheckRadioButton(hDlg, IDC_PNG, IDC_BMP, (int)path.imageformat());
CheckRadioButton(hDlg, IDC_R4TYPE1, IDC_R4TYPE2, (int)path.r4Format);
@ -315,6 +320,9 @@ void PathSettings_OnCommand(HWND hDlg, int id, HWND hwndCtl, UINT codeNotify)
}
}
break;
case IDC_AUTOLOADLUA:
autoLoadLua = !autoLoadLua;
break;
case IDOK:
GetDlgItemText(hDlg, IDC_ROMPATHEDIT, path.pathToRoms, MAX_PATH);

View File

@ -998,6 +998,7 @@
#define IDM_RENDER_LQ2X 60082
#define IDM_RENDER_LQ2XS 60083
#define IDC_SAVETYPE 64000
#define IDC_AUTOLOADLUA 64001
// Next default values for new objects
//

Binary file not shown.