summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/mlua_options.cpp
blob: 1a93789f52161c2f04eb855697061848ccc4b1ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "stdafx.h"

CLuaOptions::CLuaOptions(int idDialog)
	: CDlgBase(g_hInstance, idDialog), m_scripts(this, IDC_SCRIPTS)
{
}

void CLuaOptions::CreateLink(CCtrlData& ctrl, const char *szSetting, BYTE type, DWORD iValue)
{
	ctrl.CreateDbLink(MODULE, szSetting, type, iValue);
}

void CLuaOptions::CreateLink(CCtrlData& ctrl, const char *szSetting, TCHAR *szValue)
{
	ctrl.CreateDbLink(MODULE, szSetting, szValue);
}

void CLuaOptions::LoadScripts(const TCHAR *scriptDir)
{
	TCHAR searchMask[MAX_PATH];
	mir_sntprintf(searchMask, _T("%s\\%s"), scriptDir, _T("*.lua"));

	TCHAR fullPath[MAX_PATH], path[MAX_PATH];

	WIN32_FIND_DATA fd;
	HANDLE hFind = FindFirstFile(searchMask, &fd);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
			{
				mir_sntprintf(fullPath, _T("%s\\%s"), scriptDir, fd.cFileName);
				PathToRelativeT(fullPath, path);

				m_scripts.AddItem(fd.cFileName, -1, NULL, 0);
			}
		} while (FindNextFile(hFind, &fd));
		FindClose(hFind);
	}
}

void CLuaOptions::OnInitDialog()
{
	CDlgBase::OnInitDialog();

	m_scripts.EnableGroupView(TRUE);
	m_scripts.AddGroup(0, TranslateT("Common scripts"));
	m_scripts.AddGroup(1, TranslateT("Custom scripts"));

	m_scripts.AddColumn(0, _T("Script"), 300);

	WIN32_FIND_DATA fd;
	HANDLE hFind = NULL;
	TCHAR scriptDir[MAX_PATH];
	TCHAR searchMask[MAX_PATH];

	FoldersGetCustomPathT(g_hCommonFolderPath, scriptDir, SIZEOF(scriptDir), VARST(COMMON_SCRIPTS_PATHT));
	mir_sntprintf(searchMask, _T("%s\\%s"), scriptDir, _T("*.lua"));
	hFind = FindFirstFile(searchMask, &fd);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
			{
				m_scripts.AddItem(fd.cFileName, -1, NULL, 0);
			}
		} while (FindNextFile(hFind, &fd));
		FindClose(hFind);
	}

	FoldersGetCustomPathT(g_hCustomFolderPath, scriptDir, SIZEOF(scriptDir), VARST(CUSTOM_SCRIPTS_PATHT));
	mir_sntprintf(searchMask, _T("%s\\%s"), scriptDir, _T("*.lua"));
	hFind = FindFirstFile(searchMask, &fd);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
			{
				m_scripts.AddItem(fd.cFileName, -1, NULL, 1);
			}
		} while (FindNextFile(hFind, &fd));
		FindClose(hFind);
	}
}