Subversion Repositories spk

Rev

Rev 170 | Rev 197 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
	{
170 cycrow 38
		Utils::String file = p->icon()->filePointer();
39
		if (!file.empty())
1 cycrow 40
		{
170 cycrow 41
			file = file.findReplace("/", "\\").findReplace("\\\\", "\\");
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;
158 cycrow 54
				if ( p->iconExt().Compare("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
				}
158 cycrow 60
				else if ( p->iconExt().Compare("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
	{
170 cycrow 98
		Utils::String file = p->icon()->filePointer();
99
		if (!file.empty())
1 cycrow 100
		{
170 cycrow 101
			file = file.findReplace("/", "\\").findReplace("\\\\", "\\");
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
 
137
	bool WriteRegistryValue(CyString rKey, CyString rValue)
138
	{
191 cycrow 139
		Utils::WString first = rKey.GetToken("/", 1, 1).ToString();
1 cycrow 140
		rKey = rKey.GetToken("/", 2);
141
 
142
		RegistryKey ^startKey = nullptr;
143
		if ( first.Compare("HKCU") )
144
			startKey = Registry::CurrentUser;
145
		else if ( first.Compare("HKLM") )
146
			startKey = Registry::LocalMachine;
147
 
148
		if ( startKey )
149
		{
191 cycrow 150
			Utils::WString value = rKey.GetToken("/", rKey.NumToken("/")).ToString();
1 cycrow 151
			rKey = rKey.GetToken("/", 1, rKey.NumToken("/") - 1);
191 cycrow 152
			RegistryKey ^writeKey = startKey->OpenSubKey(_US(rKey.FindReplace("/", "\\").ToString()), true);
1 cycrow 153
			if ( writeKey )
154
			{
191 cycrow 155
				writeKey->SetValue(_US(value), _US(rValue.ToString()));
1 cycrow 156
				return true;
157
			}
158
		}
159
 
160
		return false;
161
	}
162
 
163
	System::String ^ReadRegistryValue(CyString rKey)
164
	{
191 cycrow 165
		Utils::WString first = rKey.GetToken("/", 1, 1).ToString();
1 cycrow 166
		rKey = rKey.GetToken("/", 2);
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
		{
191 cycrow 178
			Utils::WString value = rKey.GetToken("/", rKey.NumToken("/")).ToString();
1 cycrow 179
			rKey = rKey.GetToken("/", 1, rKey.NumToken("/") - 1);
191 cycrow 180
			RegistryKey ^readKey = startKey->OpenSubKey(_US(rKey.FindReplace("/", "\\").ToString()), 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
}