| 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 | 	{
 | 
        
           |  |  | 27 | 		System::String ^str = "V" + SystemStringFromCyString(CyString::CreateFromFloat(version, 2));
 | 
        
           |  |  | 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 | 							}
 | 
        
           |  |  | 82 | 						} catch (System::ArgumentException ^e) {
 | 
        
           |  |  | 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 | 	{
 | 
        
           |  |  | 139 | 		CyString first = rKey.GetToken("/", 1, 1);
 | 
        
           |  |  | 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 | 		{
 | 
        
           |  |  | 150 | 			CyString value = rKey.GetToken("/", rKey.NumToken("/"));
 | 
        
           |  |  | 151 | 			rKey = rKey.GetToken("/", 1, rKey.NumToken("/") - 1);
 | 
        
           |  |  | 152 | 			RegistryKey ^writeKey = startKey->OpenSubKey(SystemStringFromCyString(rKey.FindReplace("/", "\\")), true);
 | 
        
           |  |  | 153 | 			if ( writeKey )
 | 
        
           |  |  | 154 | 			{
 | 
        
           |  |  | 155 | 				writeKey->SetValue(SystemStringFromCyString(value), SystemStringFromCyString(rValue));
 | 
        
           |  |  | 156 | 				return true;
 | 
        
           |  |  | 157 | 			}
 | 
        
           |  |  | 158 | 		}
 | 
        
           |  |  | 159 |   | 
        
           |  |  | 160 | 		return false;
 | 
        
           |  |  | 161 | 	}
 | 
        
           |  |  | 162 |   | 
        
           |  |  | 163 | 	System::String ^ReadRegistryValue(CyString rKey)
 | 
        
           |  |  | 164 | 	{
 | 
        
           |  |  | 165 | 		CyString first = rKey.GetToken("/", 1, 1);
 | 
        
           |  |  | 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 | 		{
 | 
        
           |  |  | 178 | 			CyString value = rKey.GetToken("/", rKey.NumToken("/"));
 | 
        
           |  |  | 179 | 			rKey = rKey.GetToken("/", 1, rKey.NumToken("/") - 1);
 | 
        
           |  |  | 180 | 			RegistryKey ^readKey = startKey->OpenSubKey(SystemStringFromCyString(rKey.FindReplace("/", "\\")), true);
 | 
        
           |  |  | 181 | 			if ( readKey )
 | 
        
           |  |  | 182 | 				strKey = System::Convert::ToString(readKey->GetValue(SystemStringFromCyString(value)));
 | 
        
           |  |  | 183 | 		}
 | 
        
           |  |  | 184 |   | 
        
           |  |  | 185 | 		return strKey;
 | 
        
           |  |  | 186 | 	}
 | 
        
           |  |  | 187 | }
 |