Rev 197 | Blame | Compare with Previous | Last modification | View Log | RSS feed
// stdafx.cpp : source file that includes just the standard includes
// PluginManager.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
using namespace System;
using namespace Runtime::InteropServices;
using namespace System::Drawing;
namespace PluginManager {
System::String ^GetProgramName(bool advanced)
{
System::String ^str = "X-Universe Plugin Manager ";
if ( !advanced )
str += "Lite";
else
str += "Advanced";
return str;
}
System::String ^GetVersionString()
{
return GetVersionString((float)PMLVERSION, (int)PMLBETA);
}
System::String ^GetVersionString(float version, int beta)
{
System::String ^str = "V" + _US(Utils::WString::FromFloat(version, 2));
// beta version
if ( beta > 0 )
str += " (Beta " + beta + ")";
// RC release
else if ( beta < 0 )
str += " (RC " + (0 - beta) + ")";
return str;
}
void DisplayListIcon(CBaseFile *p, ListView ^list, ListViewItem ^item)
{
Utils::WString file = p->icon()->filePointer();
if (!file.empty())
{
file = file.findReplace(L"/", L"\\").findReplace(L"\\\\", L"\\");
bool doIcon = false;
System::String ^sFile = _US(file);
int index = list->SmallImageList->Images->IndexOfKey(sFile);
if ( index != -1 )
{
item->ImageIndex = index;
return;
}
if ( System::IO::File::Exists(sFile) )
{
doIcon = true;
if ( p->iconExt().Compare(L"bmp") )
{
list->SmallImageList->Images->Add(Bitmap::FromFile(sFile));
if ( list->SmallImageList != list->LargeImageList )
list->LargeImageList->Images->Add(Bitmap::FromFile(sFile));
}
else if ( p->iconExt().Compare(L"ico") )
{
list->SmallImageList->Images->Add(gcnew System::Drawing::Icon(sFile));
if ( list->SmallImageList != list->LargeImageList )
list->LargeImageList->Images->Add(gcnew System::Drawing::Icon(sFile));
}
else
{
doIcon = false;
if ( System::IO::File::Exists(sFile) ) {
try {
Bitmap ^myBitmap = gcnew Bitmap(sFile);
if ( myBitmap )
{
IntPtr Hicon = myBitmap->GetHicon();
System::Drawing::Icon ^newIcon = ::Icon::FromHandle(Hicon);
list->SmallImageList->Images->Add(newIcon);
if ( list->SmallImageList != list->LargeImageList )
list->LargeImageList->Images->Add(newIcon);
doIcon = true;
}
} catch (System::ArgumentException ^) {
}
}
}
}
if ( doIcon )
{
list->SmallImageList->Images->SetKeyName(list->SmallImageList->Images->Count - 1, sFile);
item->ImageIndex = list->SmallImageList->Images->Count - 1;
}
}
}
void DisplayContextIcon(CBaseFile *p, ToolStripMenuItem ^item, ImageList ^list)
{
Utils::WString file = p->icon()->filePointer();
if (!file.empty())
{
file = file.findReplace(L"/", L"\\").findReplace(L"\\\\", L"\\");
PluginManager::DisplayContextIcon(_US(file), item, list);
}
}
void DisplayContextIcon(System::String ^filename, ToolStripMenuItem ^item, ImageList ^list)
{
if ( System::IO::File::Exists(filename) )
{
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")
{
if ( list )
{
list->Images->Add(filename, Bitmap::FromFile(filename));
item->Image = list->Images[list->Images->IndexOfKey(filename)];
}
else
item->Image = Bitmap::FromFile(filename);
}
else
{
Bitmap ^myBitmap = gcnew Bitmap(filename);
if ( myBitmap )
{
if ( list )
{
list->Images->Add(filename, myBitmap);
item->Image = list->Images[list->Images->IndexOfKey(filename)];
}
else
item->Image = myBitmap;
}
}
}
}
bool WriteRegistryValue(const Utils::WString &a_rKey, const Utils::WString &rValue)
{
Utils::WString first = a_rKey.token(L"/", 1);
Utils::WString rKey = a_rKey.tokens(L"/", 2);
RegistryKey ^startKey = nullptr;
if ( first.Compare(L"HKCU") )
startKey = Registry::CurrentUser;
else if ( first.Compare(L"HKLM") )
startKey = Registry::LocalMachine;
if ( startKey )
{
Utils::WString value = rKey.token(L"/", rKey.countToken(L"/"));
rKey = rKey.tokens(L"/", 1, rKey.countToken(L"/") - 1);
RegistryKey ^writeKey = startKey->OpenSubKey(_US(rKey.findReplace(L"/", L"\\")), true);
if ( writeKey )
{
writeKey->SetValue(_US(value), _US(rValue));
return true;
}
}
return false;
}
System::String ^ReadRegistryValue(const Utils::WString &a_rKey)
{
Utils::WString first = a_rKey.token(L"/", 1);
Utils::WString rKey = a_rKey.tokens(L"/", 2);
System::String ^strKey;
RegistryKey ^startKey = nullptr;
if ( first.Compare(L"HKCU") )
startKey = Registry::CurrentUser;
else if ( first.Compare(L"HKLM") )
startKey = Registry::LocalMachine;
if ( startKey )
{
Utils::WString value = rKey.token(L"/", rKey.countToken(L"/"));
rKey = rKey.tokens(L"/", 1, rKey.countToken(L"/") - 1);
RegistryKey ^readKey = startKey->OpenSubKey(_US(rKey.findReplace(L"/", L"\\")), true);
if ( readKey )
strKey = System::Convert::ToString(readKey->GetValue(_US(value)));
}
return strKey;
}
}