MTE_Util.cpp
2.3 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "StdAfx.h"
#include "MTE_Util.h"
char *get_modis_exe_path()
{
int i;
static char modis_exe_path[1024];
GetModuleFileName(NULL, modis_exe_path, 1024 - 1);
for (i = strlen(modis_exe_path) - 1; i >= 0; i--)
{
if (modis_exe_path[i] == '\\')
{
modis_exe_path[i] = 0;
break;
}
}
return modis_exe_path;
}
char *get_convert_exe_full_path()
{
char *modis_exe_path;
static char convert_exe_path[1024];
WIN32_FIND_DATA fd;
modis_exe_path = get_modis_exe_path();
// search resource generator directory first, and then modis directory
sprintf(convert_exe_path, "%s\\..\\..\\..\\plutommi\\Customer\\ResGenerator\\convert.exe", modis_exe_path);
if (FindFirstFile(convert_exe_path, &fd) == INVALID_HANDLE_VALUE)
{
// try modis.exe directory
sprintf(convert_exe_path, "%s\\convert.exe", modis_exe_path);
if (FindFirstFile(convert_exe_path, &fd) == INVALID_HANDLE_VALUE)
{
return NULL;
}
}
return convert_exe_path;
}
char *get_temp_path()
{
static char temp_path[1024];
temp_path[1024 - 1] = 0;
GetTempPath(1024 - 1, temp_path);
return temp_path;
}
BOOL RunProcess(char* processname)
{
// Start the child process.
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
return CreateProcess( NULL, processname, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
}
MoDISFileDialogW::MoDISFileDialogW( HWND hwndOwner, LPCWSTR lpstrDefExtW,
LPWSTR lpszFileNameW, DWORD Flags, LPCWSTR lpstrFilterW)
{
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwndOwner;
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = L'\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = lpstrFilterW;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = lpszFileNameW;
ofn.nMaxFileTitle = sizeof(lpszFileNameW);
ofn.lpstrInitialDir = NULL;
ofn.lpstrDefExt = lpstrDefExtW;
ofn.Flags = Flags;
}
MoDISFileDialogW::MoDISFileDialogW( OPENFILENAMEW &ofnin )
{
ofn = ofnin;
}
BOOL MoDISFileDialogW::SaveFile()
{
return ::GetSaveFileNameW( &ofn ) ;
}
BOOL MoDISFileDialogW::LoadFile()
{
return ::GetOpenFileNameW( &ofn ) ;
}
std::wstring MoDISFileDialogW::GetFileNameW()
{
return std::wstring( szFile ) ;
}
std::string MoDISFileDialogW::GetFileNameA()
{
USES_CONVERSION ;
return std::string( W2A(szFile));
}