| 1 |
cycrow |
1 |
// stdafx.cpp : source file that includes just the standard includes
|
|
|
2 |
// PluginManager.pch will be the pre-compiled header
|
|
|
3 |
// stdafx.obj will contain the pre-compiled type information
|
|
|
4 |
|
|
|
5 |
#include "stdafx.h"
|
|
|
6 |
|
|
|
7 |
using namespace System;
|
|
|
8 |
using namespace Runtime::InteropServices;
|
|
|
9 |
using namespace System::Drawing;
|
|
|
10 |
|
|
|
11 |
namespace PluginManager {
|
|
|
12 |
System::String ^GetProgramName(bool advanced)
|
|
|
13 |
{
|
|
|
14 |
System::String ^str = "X-Universe Plugin Manager ";
|
|
|
15 |
if ( !advanced )
|
|
|
16 |
str += "Lite";
|
|
|
17 |
else
|
|
|
18 |
str += "Advanced";
|
|
|
19 |
return str;
|
|
|
20 |
}
|
|
|
21 |
System::String ^GetVersionString()
|
|
|
22 |
{
|
|
|
23 |
return GetVersionString((float)PMLVERSION, (int)PMLBETA);
|
|
|
24 |
}
|
|
|
25 |
System::String ^GetVersionString(float version, int beta)
|
|
|
26 |
{
|
| 191 |
cycrow |
27 |
System::String ^str = "V" + _US(Utils::WString::FromFloat(version, 2));
|
| 1 |
cycrow |
28 |
// beta version
|
|
|
29 |
if ( beta > 0 )
|
|
|
30 |
str += " (Beta " + beta + ")";
|
|
|
31 |
// RC release
|
|
|
32 |
else if ( beta < 0 )
|
|
|
33 |
str += " (RC " + (0 - beta) + ")";
|
|
|
34 |
return str;
|
|
|
35 |
}
|
|
|
36 |
void DisplayListIcon(CBaseFile *p, ListView ^list, ListViewItem ^item)
|
|
|
37 |
{
|
| 197 |
cycrow |
38 |
Utils::WString file = p->icon()->filePointer();
|
| 170 |
cycrow |
39 |
if (!file.empty())
|
| 1 |
cycrow |
40 |
{
|
| 197 |
cycrow |
41 |
file = file.findReplace(L"/", L"\\").findReplace(L"\\\\", L"\\");
|
| 1 |
cycrow |
42 |
bool doIcon = false;
|
| 170 |
cycrow |
43 |
System::String ^sFile = _US(file);
|
| 1 |
cycrow |
44 |
int index = list->SmallImageList->Images->IndexOfKey(sFile);
|
|
|
45 |
if ( index != -1 )
|
|
|
46 |
{
|
|
|
47 |
item->ImageIndex = index;
|
|
|
48 |
return;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
if ( System::IO::File::Exists(sFile) )
|
|
|
52 |
{
|
|
|
53 |
doIcon = true;
|
| 197 |
cycrow |
54 |
if ( p->iconExt().Compare(L"bmp") )
|
| 1 |
cycrow |
55 |
{
|
|
|
56 |
list->SmallImageList->Images->Add(Bitmap::FromFile(sFile));
|
|
|
57 |
if ( list->SmallImageList != list->LargeImageList )
|
|
|
58 |
list->LargeImageList->Images->Add(Bitmap::FromFile(sFile));
|
|
|
59 |
}
|
| 197 |
cycrow |
60 |
else if ( p->iconExt().Compare(L"ico") )
|
| 1 |
cycrow |
61 |
{
|
|
|
62 |
list->SmallImageList->Images->Add(gcnew System::Drawing::Icon(sFile));
|
|
|
63 |
if ( list->SmallImageList != list->LargeImageList )
|
|
|
64 |
list->LargeImageList->Images->Add(gcnew System::Drawing::Icon(sFile));
|
|
|
65 |
}
|
|
|
66 |
else
|
|
|
67 |
{
|
|
|
68 |
doIcon = false;
|
|
|
69 |
|
| 50 |
cycrow |
70 |
if ( System::IO::File::Exists(sFile) ) {
|
|
|
71 |
try {
|
|
|
72 |
Bitmap ^myBitmap = gcnew Bitmap(sFile);
|
|
|
73 |
if ( myBitmap )
|
|
|
74 |
{
|
|
|
75 |
IntPtr Hicon = myBitmap->GetHicon();
|
|
|
76 |
System::Drawing::Icon ^newIcon = ::Icon::FromHandle(Hicon);
|
|
|
77 |
list->SmallImageList->Images->Add(newIcon);
|
|
|
78 |
if ( list->SmallImageList != list->LargeImageList )
|
|
|
79 |
list->LargeImageList->Images->Add(newIcon);
|
|
|
80 |
doIcon = true;
|
|
|
81 |
}
|
| 191 |
cycrow |
82 |
} catch (System::ArgumentException ^) {
|
| 50 |
cycrow |
83 |
}
|
| 1 |
cycrow |
84 |
}
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
if ( doIcon )
|
|
|
89 |
{
|
|
|
90 |
list->SmallImageList->Images->SetKeyName(list->SmallImageList->Images->Count - 1, sFile);
|
|
|
91 |
item->ImageIndex = list->SmallImageList->Images->Count - 1;
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
void DisplayContextIcon(CBaseFile *p, ToolStripMenuItem ^item, ImageList ^list)
|
|
|
97 |
{
|
| 197 |
cycrow |
98 |
Utils::WString file = p->icon()->filePointer();
|
| 170 |
cycrow |
99 |
if (!file.empty())
|
| 1 |
cycrow |
100 |
{
|
| 197 |
cycrow |
101 |
file = file.findReplace(L"/", L"\\").findReplace(L"\\\\", L"\\");
|
| 170 |
cycrow |
102 |
PluginManager::DisplayContextIcon(_US(file), item, list);
|
| 1 |
cycrow |
103 |
}
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
void DisplayContextIcon(System::String ^filename, ToolStripMenuItem ^item, ImageList ^list)
|
|
|
107 |
{
|
|
|
108 |
if ( System::IO::File::Exists(filename) )
|
|
|
109 |
{
|
|
|
110 |
if ( System::IO::FileInfo(filename).Extension == "bmp" || System::IO::FileInfo(filename).Extension == "BMP" || System::IO::FileInfo(filename).Extension == "ico" || System::IO::FileInfo(filename).Extension == "ICO")
|
|
|
111 |
{
|
|
|
112 |
if ( list )
|
|
|
113 |
{
|
|
|
114 |
list->Images->Add(filename, Bitmap::FromFile(filename));
|
|
|
115 |
item->Image = list->Images[list->Images->IndexOfKey(filename)];
|
|
|
116 |
}
|
|
|
117 |
else
|
|
|
118 |
item->Image = Bitmap::FromFile(filename);
|
|
|
119 |
}
|
|
|
120 |
else
|
|
|
121 |
{
|
|
|
122 |
Bitmap ^myBitmap = gcnew Bitmap(filename);
|
|
|
123 |
if ( myBitmap )
|
|
|
124 |
{
|
|
|
125 |
if ( list )
|
|
|
126 |
{
|
|
|
127 |
list->Images->Add(filename, myBitmap);
|
|
|
128 |
item->Image = list->Images[list->Images->IndexOfKey(filename)];
|
|
|
129 |
}
|
|
|
130 |
else
|
|
|
131 |
item->Image = myBitmap;
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
|
| 197 |
cycrow |
137 |
bool WriteRegistryValue(const Utils::WString &a_rKey, const Utils::WString &rValue)
|
| 1 |
cycrow |
138 |
{
|
| 197 |
cycrow |
139 |
Utils::WString first = a_rKey.token(L"/", 1);
|
|
|
140 |
Utils::WString rKey = a_rKey.tokens(L"/", 2);
|
| 1 |
cycrow |
141 |
|
|
|
142 |
RegistryKey ^startKey = nullptr;
|
| 197 |
cycrow |
143 |
if ( first.Compare(L"HKCU") )
|
| 1 |
cycrow |
144 |
startKey = Registry::CurrentUser;
|
| 197 |
cycrow |
145 |
else if ( first.Compare(L"HKLM") )
|
| 1 |
cycrow |
146 |
startKey = Registry::LocalMachine;
|
|
|
147 |
|
|
|
148 |
if ( startKey )
|
|
|
149 |
{
|
| 197 |
cycrow |
150 |
Utils::WString value = rKey.token(L"/", rKey.countToken(L"/"));
|
|
|
151 |
rKey = rKey.tokens(L"/", 1, rKey.countToken(L"/") - 1);
|
|
|
152 |
RegistryKey ^writeKey = startKey->OpenSubKey(_US(rKey.findReplace(L"/", L"\\")), true);
|
| 1 |
cycrow |
153 |
if ( writeKey )
|
|
|
154 |
{
|
| 197 |
cycrow |
155 |
writeKey->SetValue(_US(value), _US(rValue));
|
| 1 |
cycrow |
156 |
return true;
|
|
|
157 |
}
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
return false;
|
|
|
161 |
}
|
|
|
162 |
|
| 197 |
cycrow |
163 |
System::String ^ReadRegistryValue(const Utils::WString &a_rKey)
|
| 1 |
cycrow |
164 |
{
|
| 197 |
cycrow |
165 |
Utils::WString first = a_rKey.token(L"/", 1);
|
|
|
166 |
Utils::WString rKey = a_rKey.tokens(L"/", 2);
|
| 1 |
cycrow |
167 |
|
|
|
168 |
System::String ^strKey;
|
|
|
169 |
|
|
|
170 |
RegistryKey ^startKey = nullptr;
|
|
|
171 |
if ( first.Compare("HKCU") )
|
|
|
172 |
startKey = Registry::CurrentUser;
|
|
|
173 |
else if ( first.Compare("HKLM") )
|
|
|
174 |
startKey = Registry::LocalMachine;
|
|
|
175 |
|
|
|
176 |
if ( startKey )
|
|
|
177 |
{
|
| 197 |
cycrow |
178 |
Utils::WString value = rKey.token(L"/", rKey.countToken(L"/"));
|
|
|
179 |
rKey = rKey.tokens(L"/", 1, rKey.countToken(L"/") - 1);
|
|
|
180 |
RegistryKey ^readKey = startKey->OpenSubKey(_US(rKey.findReplace(L"/", L"\\")), true);
|
| 1 |
cycrow |
181 |
if ( readKey )
|
| 191 |
cycrow |
182 |
strKey = System::Convert::ToString(readKey->GetValue(_US(value)));
|
| 1 |
cycrow |
183 |
}
|
|
|
184 |
|
|
|
185 |
return strKey;
|
|
|
186 |
}
|
|
|
187 |
}
|