| 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 | 
           	{
  | 
        
        
            | 
            | 
           38 | 
           		CyString file = p->GetIcon()->GetFilePointer();
  | 
        
        
            | 
            | 
           39 | 
           		if ( !file.Empty() )
  | 
        
        
            | 
            | 
           40 | 
           		{
  | 
        
        
            | 
            | 
           41 | 
           			file = file.FindReplace("/", "\\").FindReplace("\\\\", "\\");
  | 
        
        
            | 
            | 
           42 | 
           			bool doIcon = false;
  | 
        
        
            | 
            | 
           43 | 
           			System::String ^sFile = SystemStringFromCyString(file);
  | 
        
        
            | 
            | 
           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;
  | 
        
        
            | 
            | 
           54 | 
           				if ( p->GetIconExt().Compare("bmp") )
  | 
        
        
            | 
            | 
           55 | 
           				{
  | 
        
        
            | 
            | 
           56 | 
           					list->SmallImageList->Images->Add(Bitmap::FromFile(sFile));
  | 
        
        
            | 
            | 
           57 | 
           					if ( list->SmallImageList != list->LargeImageList )
  | 
        
        
            | 
            | 
           58 | 
           						list->LargeImageList->Images->Add(Bitmap::FromFile(sFile));
  | 
        
        
            | 
            | 
           59 | 
           				}
  | 
        
        
            | 
            | 
           60 | 
           				else if ( p->GetIconExt().Compare("ico") )
  | 
        
        
            | 
            | 
           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 | 
              | 
        
        
            | 
            | 
           70 | 
           					Bitmap ^myBitmap = gcnew Bitmap(sFile);
  | 
        
        
            | 
            | 
           71 | 
           					if ( myBitmap )
  | 
        
        
            | 
            | 
           72 | 
           					{
  | 
        
        
            | 
            | 
           73 | 
           						IntPtr Hicon = myBitmap->GetHicon();
  | 
        
        
            | 
            | 
           74 | 
           						System::Drawing::Icon ^newIcon = ::Icon::FromHandle(Hicon);
  | 
        
        
            | 
            | 
           75 | 
           						list->SmallImageList->Images->Add(newIcon);
  | 
        
        
            | 
            | 
           76 | 
           						if ( list->SmallImageList != list->LargeImageList )
  | 
        
        
            | 
            | 
           77 | 
           							list->LargeImageList->Images->Add(newIcon);
  | 
        
        
            | 
            | 
           78 | 
           						doIcon = true;
  | 
        
        
            | 
            | 
           79 | 
           					}
  | 
        
        
            | 
            | 
           80 | 
           				}
  | 
        
        
            | 
            | 
           81 | 
           			}
  | 
        
        
            | 
            | 
           82 | 
              | 
        
        
            | 
            | 
           83 | 
           			if ( doIcon )
  | 
        
        
            | 
            | 
           84 | 
           			{
  | 
        
        
            | 
            | 
           85 | 
           				list->SmallImageList->Images->SetKeyName(list->SmallImageList->Images->Count - 1, sFile);
  | 
        
        
            | 
            | 
           86 | 
           				item->ImageIndex = list->SmallImageList->Images->Count - 1;
  | 
        
        
            | 
            | 
           87 | 
           			}
  | 
        
        
            | 
            | 
           88 | 
           		}
  | 
        
        
            | 
            | 
           89 | 
           	}
  | 
        
        
            | 
            | 
           90 | 
              | 
        
        
            | 
            | 
           91 | 
           	void DisplayContextIcon(CBaseFile *p, ToolStripMenuItem ^item, ImageList ^list)
  | 
        
        
            | 
            | 
           92 | 
           	{
  | 
        
        
            | 
            | 
           93 | 
           		CyString file = p->GetIcon()->GetFilePointer();
  | 
        
        
            | 
            | 
           94 | 
           		if ( !file.Empty() )
  | 
        
        
            | 
            | 
           95 | 
           		{
  | 
        
        
            | 
            | 
           96 | 
           			file = file.FindReplace("/", "\\").FindReplace("\\\\", "\\");
  | 
        
        
            | 
            | 
           97 | 
           			PluginManager::DisplayContextIcon(SystemStringFromCyString(file), item, list);
  | 
        
        
            | 
            | 
           98 | 
           		}
  | 
        
        
            | 
            | 
           99 | 
           	}
  | 
        
        
            | 
            | 
           100 | 
              | 
        
        
            | 
            | 
           101 | 
           	void DisplayContextIcon(System::String ^filename, ToolStripMenuItem ^item, ImageList ^list)
  | 
        
        
            | 
            | 
           102 | 
           	{
  | 
        
        
            | 
            | 
           103 | 
           		if ( System::IO::File::Exists(filename) )
  | 
        
        
            | 
            | 
           104 | 
           		{
  | 
        
        
            | 
            | 
           105 | 
           			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")
  | 
        
        
            | 
            | 
           106 | 
           			{
  | 
        
        
            | 
            | 
           107 | 
           				if ( list )
  | 
        
        
            | 
            | 
           108 | 
           				{
  | 
        
        
            | 
            | 
           109 | 
           					list->Images->Add(filename, Bitmap::FromFile(filename));
  | 
        
        
            | 
            | 
           110 | 
           					item->Image = list->Images[list->Images->IndexOfKey(filename)];
  | 
        
        
            | 
            | 
           111 | 
           				}
  | 
        
        
            | 
            | 
           112 | 
           				else
  | 
        
        
            | 
            | 
           113 | 
           					item->Image = Bitmap::FromFile(filename);
  | 
        
        
            | 
            | 
           114 | 
           			}
  | 
        
        
            | 
            | 
           115 | 
           			else
  | 
        
        
            | 
            | 
           116 | 
           			{
  | 
        
        
            | 
            | 
           117 | 
           				Bitmap ^myBitmap = gcnew Bitmap(filename);
  | 
        
        
            | 
            | 
           118 | 
           				if ( myBitmap )
  | 
        
        
            | 
            | 
           119 | 
           				{
  | 
        
        
            | 
            | 
           120 | 
           					if ( list )
  | 
        
        
            | 
            | 
           121 | 
           					{
  | 
        
        
            | 
            | 
           122 | 
           						list->Images->Add(filename, myBitmap);
  | 
        
        
            | 
            | 
           123 | 
           						item->Image = list->Images[list->Images->IndexOfKey(filename)];
  | 
        
        
            | 
            | 
           124 | 
           					}
  | 
        
        
            | 
            | 
           125 | 
           					else
  | 
        
        
            | 
            | 
           126 | 
           						item->Image = myBitmap;
  | 
        
        
            | 
            | 
           127 | 
           				}
  | 
        
        
            | 
            | 
           128 | 
           			}
  | 
        
        
            | 
            | 
           129 | 
           		}
  | 
        
        
            | 
            | 
           130 | 
           	}
  | 
        
        
            | 
            | 
           131 | 
              | 
        
        
            | 
            | 
           132 | 
           	bool WriteRegistryValue(CyString rKey, CyString rValue)
  | 
        
        
            | 
            | 
           133 | 
           	{
  | 
        
        
            | 
            | 
           134 | 
           		CyString first = rKey.GetToken("/", 1, 1);
  | 
        
        
            | 
            | 
           135 | 
           		rKey = rKey.GetToken("/", 2);
  | 
        
        
            | 
            | 
           136 | 
              | 
        
        
            | 
            | 
           137 | 
           		RegistryKey ^startKey = nullptr;
  | 
        
        
            | 
            | 
           138 | 
           		if ( first.Compare("HKCU") )
  | 
        
        
            | 
            | 
           139 | 
           			startKey = Registry::CurrentUser;
  | 
        
        
            | 
            | 
           140 | 
           		else if ( first.Compare("HKLM") )
  | 
        
        
            | 
            | 
           141 | 
           			startKey = Registry::LocalMachine;
  | 
        
        
            | 
            | 
           142 | 
              | 
        
        
            | 
            | 
           143 | 
           		if ( startKey )
  | 
        
        
            | 
            | 
           144 | 
           		{
  | 
        
        
            | 
            | 
           145 | 
           			CyString value = rKey.GetToken("/", rKey.NumToken("/"));
  | 
        
        
            | 
            | 
           146 | 
           			rKey = rKey.GetToken("/", 1, rKey.NumToken("/") - 1);
  | 
        
        
            | 
            | 
           147 | 
           			RegistryKey ^writeKey = startKey->OpenSubKey(SystemStringFromCyString(rKey.FindReplace("/", "\\")), true);
  | 
        
        
            | 
            | 
           148 | 
           			if ( writeKey )
  | 
        
        
            | 
            | 
           149 | 
           			{
  | 
        
        
            | 
            | 
           150 | 
           				writeKey->SetValue(SystemStringFromCyString(value), SystemStringFromCyString(rValue));
  | 
        
        
            | 
            | 
           151 | 
           				return true;
  | 
        
        
            | 
            | 
           152 | 
           			}
  | 
        
        
            | 
            | 
           153 | 
           		}
  | 
        
        
            | 
            | 
           154 | 
              | 
        
        
            | 
            | 
           155 | 
           		return false;
  | 
        
        
            | 
            | 
           156 | 
           	}
  | 
        
        
            | 
            | 
           157 | 
              | 
        
        
            | 
            | 
           158 | 
           	System::String ^ReadRegistryValue(CyString rKey)
  | 
        
        
            | 
            | 
           159 | 
           	{
  | 
        
        
            | 
            | 
           160 | 
           		CyString first = rKey.GetToken("/", 1, 1);
  | 
        
        
            | 
            | 
           161 | 
           		rKey = rKey.GetToken("/", 2);
  | 
        
        
            | 
            | 
           162 | 
              | 
        
        
            | 
            | 
           163 | 
           		System::String ^strKey;
  | 
        
        
            | 
            | 
           164 | 
              | 
        
        
            | 
            | 
           165 | 
           		RegistryKey ^startKey = nullptr;
  | 
        
        
            | 
            | 
           166 | 
           		if ( first.Compare("HKCU") )
  | 
        
        
            | 
            | 
           167 | 
           			startKey = Registry::CurrentUser;
  | 
        
        
            | 
            | 
           168 | 
           		else if ( first.Compare("HKLM") )
  | 
        
        
            | 
            | 
           169 | 
           			startKey = Registry::LocalMachine;
  | 
        
        
            | 
            | 
           170 | 
              | 
        
        
            | 
            | 
           171 | 
           		if ( startKey )
  | 
        
        
            | 
            | 
           172 | 
           		{
  | 
        
        
            | 
            | 
           173 | 
           			CyString value = rKey.GetToken("/", rKey.NumToken("/"));
  | 
        
        
            | 
            | 
           174 | 
           			rKey = rKey.GetToken("/", 1, rKey.NumToken("/") - 1);
  | 
        
        
            | 
            | 
           175 | 
           			RegistryKey ^readKey = startKey->OpenSubKey(SystemStringFromCyString(rKey.FindReplace("/", "\\")), true);
  | 
        
        
            | 
            | 
           176 | 
           			if ( readKey )
  | 
        
        
            | 
            | 
           177 | 
           				strKey = System::Convert::ToString(readKey->GetValue(SystemStringFromCyString(value)));
  | 
        
        
            | 
            | 
           178 | 
           		}
  | 
        
        
            | 
            | 
           179 | 
              | 
        
        
            | 
            | 
           180 | 
           		return strKey;
  | 
        
        
            | 
            | 
           181 | 
           	}
  | 
        
        
            | 
            | 
           182 | 
           }
  |