Пример #1
0
LONG CMirageManager::OpenDeviceRegistryKey(CRegKey& regkeyDevice, DISPLAY_DEVICE& deviceInfo)
{
	TCHAR deviceSubkey[8];
	wcscpy(deviceSubkey, _T("DEVICE0"));

	TCHAR deviceKey[MAX_PATH];
	wcsncpy(deviceKey, deviceInfo.DeviceKey, MAX_PATH - 1);
	deviceKey[MAX_PATH - 1] = 0;
	wcsupr(deviceKey);
	if (LPCTSTR devNum = wcsstr(deviceKey, _T("\\DEVICE")))
		deviceSubkey[6] = devNum[7];

	CRegKey regkeyServices;
	CRegKey regkeyDriver;

	// trying to open key with the minimal privileges
	if (ERROR_SUCCESS != regkeyServices.Open(HKEY_LOCAL_MACHINE, MINIPORT_REGISTRY_PATH, KEY_ENUMERATE_SUB_KEYS) ||
		ERROR_SUCCESS != regkeyDriver.Open(regkeyServices, MINIPORT_NAME, KEY_ENUMERATE_SUB_KEYS) ||
		ERROR_SUCCESS != regkeyDevice.Open(regkeyDriver, deviceSubkey, KEY_SET_VALUE))
	{
		regkeyServices.Close();
		regkeyDriver.Close();
		LONG retval = regkeyServices.Create(HKEY_LOCAL_MACHINE, MINIPORT_REGISTRY_PATH, REG_NONE, 0, KEY_ENUMERATE_SUB_KEYS | KEY_CREATE_SUB_KEY);
		if (ERROR_SUCCESS != retval)
			return retval;
		retval = regkeyDriver.Create(regkeyServices, MINIPORT_NAME, REG_NONE, 0, KEY_ENUMERATE_SUB_KEYS | KEY_CREATE_SUB_KEY);
		if (ERROR_SUCCESS != retval)
			return retval;
		retval = regkeyDevice.Create(regkeyDriver, deviceSubkey, REG_NONE, 0, KEY_SET_VALUE);
		if (ERROR_SUCCESS != retval)
			return retval;
	}
	return ERROR_SUCCESS;
}
Пример #2
0
bool CDlgFileAssoc::IsExtAssignedDyn(LPWSTR extName) {

	wchar_t szKeyName[20];
	wchar_t szKeyUpr[20];
	wchar_t szKeyDesc[50];

	wcscpy(szKeyUpr, extName);
	wcsupr(szKeyUpr);

	wsprintf(szKeyName, L".%s", extName);
	wsprintf(szKeyDesc, L"Nitrogen%sFile", szKeyUpr);

	bool result = false;

	HKEY hKey;
	wchar_t buf[100];
	DWORD ln = 100;

	if (RegOpenKeyExW(HKEY_CLASSES_ROOT, szKeyName, 0, 0, &hKey) == ERROR_SUCCESS) {
		if ((RegQueryValueExW(hKey, NULL, NULL, NULL, (BYTE*)&buf, &ln) == ERROR_SUCCESS) && (strCompare(buf, szKeyDesc) == 0)) {
			result = true;
		}
		RegCloseKey(hKey);
	}

	return result;

}
Пример #3
0
void CDlgFileAssoc::ExtUnassignDyn(LPWSTR extName) {

	HKEY hKey;
	DWORD len = 100;
	wchar_t buf[100];

	wchar_t szKeyName[20];
	wchar_t szKeyUpr[20];
	wchar_t szKeyDesc[50];

	wcscpy(szKeyUpr, extName);
	wcsupr(szKeyUpr);

	wsprintf(szKeyName, L".%s", extName);
	wsprintf(szKeyDesc, L"Nitrogen%sFile", szKeyUpr);

	if (RegOpenKeyExW(HKEY_CLASSES_ROOT, szKeyName, 0, 0, &hKey) == ERROR_SUCCESS) {

		if (RegQueryValueExW(hKey, L"Nitrogen backup", NULL, NULL, (BYTE*)buf, &len) == ERROR_SUCCESS) {	

			RegSetValueExW(hKey, NULL, 0, REG_SZ, (BYTE*)buf, len);
			RegDeleteValueW(hKey, L"Nitrogen backup");
	
		} else {

			RegDeleteValueW(hKey, NULL);
	
		}
	
		RegCloseKey(hKey);
	}

	RegDeleteKey(HKEY_CLASSES_ROOT, szKeyDesc);
}
Пример #4
0
void CUIString::MakeUpper()
{
#ifdef WIN32
    wcsupr(m_pstr);
#else
    WCHAR *pstr = m_pstr;
    while(*pstr){
        *pstr = (WCHAR)toupper(*pstr);
        pstr ++;
    }
#endif // WIN32
}
Пример #5
0
STDMETHODIMP CSimple::myMethod(BSTR bstrIn, BSTR *pbstrOut)  
{
    if (bstrIn == NULL || pbstrOut == NULL)
        return E_POINTER;

    // Create a temporary CComBSTR

    CComBSTR bstrTemp(bstrIn);

    if (!bstrTemp)
        return E_OUTOFMEMORY;

    // Make string uppercase   

    wcsupr(bstrTemp);  
    
    // Return m_str member of bstrTemp

    *pbstrOut = bstrTemp.Detach();

    return S_OK;
}
Пример #6
0
//-----------------------------------------------------------------------------
// Name: UpdateSearchFields
// Object: update class members from user interface
// Parameters :
//     in  :
//     out :
//     return :
//-----------------------------------------------------------------------------
BOOL CSearch::UpdateSearchFields()
{
    GetDlgItemText(this->hWndDialog,IDC_EDIT_SEARCH_VALUE,this->SearchContent,MAX_PATH);

    this->SearchAscii=(IsDlgButtonChecked(this->hWndDialog,IDC_CHECK_SEARCH_ASCII)==BST_CHECKED);
    this->SearchMatchCase=(IsDlgButtonChecked(this->hWndDialog,IDC_CHECK_SEARCH_MATCH_CASE)==BST_CHECKED);
    this->SearchUnicode=(IsDlgButtonChecked(this->hWndDialog,IDC_CHECK_SEARCH_UNICODE)==BST_CHECKED);
    this->SearchHex=(IsDlgButtonChecked(this->hWndDialog,IDC_RADIO_SEARCH_HEX_DATA)==BST_CHECKED);
    if (this->SearchHex)
    {
        if (this->HexData)
            delete this->HexData;
        this->HexData=CStrToHex::StrHexArrayToByteArray(this->SearchContent,&this->HexDataSize);
    }
    else
    {
        GetDlgItemTextA(this->hWndDialog,IDC_EDIT_SEARCH_VALUE,this->AsciiSearchContent,MAX_PATH);
        GetDlgItemTextW(this->hWndDialog,IDC_EDIT_SEARCH_VALUE,this->UnicodeSearchContent,MAX_PATH);
        AsciiSearchContentSize=strlen(this->AsciiSearchContent);
        UnicodeSearchContentSize=wcslen(this->UnicodeSearchContent)*sizeof(wchar_t);
        if (!this->SearchMatchCase)
        {
            strupr(this->AsciiSearchContent);
            wcsupr(this->UnicodeSearchContent);
        }
    }
    // if text search, and ascii and unicode are not checked
    if ((!this->SearchHex)
            && (this->SearchAscii||this->SearchUnicode)==FALSE
       )
    {
        // default to ascii text
        this->SearchAscii=TRUE;
    }
    return TRUE;
}
Пример #7
0
void CUnicodeString::MakeUpper()
{
	wcsupr(m_Buffer);
}
Пример #8
0
/*
    010509 Carl Corcoran
*/
void CCString::upr()
{
    wcsupr(this->wszString);
}
Пример #9
0
xsWChar *xsWcsUpr(xsWChar *string)
{
	return (xsWChar *)wcsupr(string);
}
Пример #10
0
// Main Initialization
int wmain (int argc, wchar_t **argv)
{
    vector<wstring>       Drives;
    vector<Defragment *> Defrags;
    DefragType           DefragMode = DefragInvalid;

    PrintBanner ();

    // Parse command line arguments
    bool ValidCmdLine = false;
    for (int c = 0; c < argc; c++)
    {
        if (wcslen(argv[c]) == 2  &&  argv[c][1] == L':')
        {
            Drives.push_back (wcsupr(argv[c]));
        }
        else
        if (argv[c][0] == L'-'  ||  argv[c][0] == L'/'  &&  wcslen(argv[c]) == 2)
        {
            switch (tolower(argv[c][1]))
            {
                case L'?' :
                case L'h' :
                    FraggerHelp ();
                    return (0);

                case L'f' :
                    if (DefragMode != DefragInvalid)
                    {
                        ValidCmdLine = false;
                        break;
                    }
                    DefragMode = DefragFast;
                    ValidCmdLine = true;
                    break;

                case L'e' :
                    if (DefragMode != DefragInvalid)
                    {
                        ValidCmdLine = false;
                        break;
                    }
                    DefragMode = DefragExtensive;
                    ValidCmdLine = true;
                    break;

            }
        }
    }

    if (DefragMode == DefragInvalid)
        ValidCmdLine = false;

    if (!ValidCmdLine)
    {
        wprintf (L"Invalid command-line options. Use '%s -?' for help.\n", argv[0]);
        return (0);
    }

    // Check OS requirements
    if (!CheckWinVer())
    {
        wprintf (L"Fatal Error: This program requires Windows 2000.\n");
        return (0);
    }

	for (size_t d = 0; d < Drives.size (); d++)
    {
        HANDLE TossMe;
        Defrags.push_back (StartDefragThread (Drives[d], DefragMode, TossMe));
    }

    for (size_t d = 0; d < Drives.size () - 1; d++)
        wprintf (L"\n ");

    bool Continue = true;
    HANDLE Screen;

    Screen = GetStdHandle (STD_OUTPUT_HANDLE);
    while (Continue)
    {
        Sleep (25);

        // Get current screen coords
        CONSOLE_SCREEN_BUFFER_INFO ScreenInfo;

        GetConsoleScreenBufferInfo (Screen, &ScreenInfo);

        // Now set back to the beginning
        ScreenInfo.dwCursorPosition.X = 0;
        ScreenInfo.dwCursorPosition.Y -= Drives.size();
        SetConsoleCursorPosition (Screen, ScreenInfo.dwCursorPosition);

        for (size_t d = 0; d < Drives.size (); d++)
        {
            wprintf (L"\n%6.2f%% %-70s", Defrags[d]->GetStatusPercent(), Defrags[d]->GetStatusString().c_str());
        }

        // Determine if we should keep going
        Continue = false;
        for (size_t d = 0; d < Drives.size (); d++)
        {
            if (!Defrags[d]->IsDoneYet()  &&  !Defrags[d]->HasError())
                Continue = true;
        }
    }

#if 0
    // Loop through the drives list
    for (int d = 0; d < Drives.size(); d++)
    {
        DriveVolume *Drive;

        Drive = new DriveVolume;

        // First thing: build a file list.
        wprintf (L"Opening volume %s ...", Drives[d].c_str());
        if (!Drive->Open (Drives[d]))
        {
            wprintf (L"FAILED\n\n");
            delete Drive;
            continue;
        }
        wprintf (L"\n");

        wprintf (L"    Getting drive bitmap ...");
        if (!Drive->GetBitmap ())
        {
            wprintf (L"FAILED\n\n");
            delete Drive;
            continue;
        }
        wprintf (L"\n");

        wprintf (L"    Obtaining drive geometry ...");
        if (!Drive->ObtainInfo ())
        {
            wprintf (L"FAILED\n\n");
            delete Drive;
            continue;
        }
        wprintf (L"\n");

        wprintf (L"    Building file database for drive %s ...", Drives[d].c_str());
        if (!Drive->BuildFileList ())
        {
            wprintf (L"FAILED\n\n");
            delete Drive;
            continue;
        }
        wprintf (L"\n");

        wprintf (L"    %u files\n", Drive->GetDBFileCount ());

        // Analyze only?
        if (DefragMode == DefragAnalyze)
        {
            uint64 UsedBytes  = 0;  // total bytes used, with cluster size considerations
            uint64 TotalBytes = 0;  // total bytes used
            uint64 SlackBytes = 0;  // wasted space due to slack
            uint32 Fragged    = 0;  // fragmented files

            wprintf (L"    Analyzing ...");
            if (VerboseMode)
                wprintf (L"\n");

            for (int i = 0; i < Drive->GetDBFileCount(); i++)
            {
                uint64 Used;
                uint64 Slack;
                FileInfo Info;

                Info = Drive->GetDBFile (i);

                // Compute total used disk space
                Used = ((Info.Size + Drive->GetClusterSize() - 1) / Drive->GetClusterSize()) * Drive->GetClusterSize();
                Slack = Used - Info.Size;

                UsedBytes += Used;
                SlackBytes += Slack;
                TotalBytes += Info.Size;

                if (VerboseMode)
                {
                    wprintf (L"    %s%s, ", Drive->GetDBDir (Info.DirIndice).c_str(), Info.Name.c_str());

                    if (Info.Attributes.AccessDenied)
                        wprintf (L"access was denied\n");
                    else
                    {
                        if (Info.Attributes.Unmovable == 1)
                            wprintf (L"unmovable, ");

                        wprintf (L"%I64u bytes, %I64u bytes on disk, %I64u bytes slack, %u fragments\n",
                            Info.Size, Used, Slack, Info.Fragments.size());
                    }
                }

                if (Info.Fragments.size() > 1)
                    Fragged++;
            }

            if (!VerboseMode)
                wprintf (L"\n");

            // TODO: Make it not look like ass
            wprintf (L"\n");
            wprintf (L"    Overall Analysis\n");
            wprintf (L"    ----------------\n");
            wprintf (L"    %u clusters\n", Drive->GetClusterCount ());
            wprintf (L"    %u bytes per cluster\n", Drive->GetClusterSize());
            wprintf (L"    %I64u total bytes on drive\n", (uint64)Drive->GetClusterCount() * (uint64)Drive->GetClusterSize());
            wprintf (L"\n");
            wprintf (L"    %u files\n", Drive->GetDBFileCount ());
            wprintf (L"    %u contiguous files\n", Drive->GetDBFileCount () - Fragged);
            wprintf (L"    %u fragmented files\n", Fragged);
            wprintf (L"\n");
            wprintf (L"    %I64u bytes\n", TotalBytes);
            wprintf (L"    %I64u bytes on disk\n", UsedBytes);
            wprintf (L"    %I64u bytes slack\n", SlackBytes);
        }

        // Fast defragment!
        if (DefragMode == DefragFast  ||  DefragMode == DefragExtensive)
        {
            uint32 i;
            uint64 FirstFreeLCN;
            wchar_t PrintName[80];
            int Width = 66;

            if (DefragMode == DefragFast)
                wprintf (L"    Performing fast file defragmentation ...\n");
            else
            if (DefragMode == DefragExtensive)
                wprintf (L"    Performing extensive file defragmentation\n");

            // Find first free LCN for speedier searches ...
            Drive->FindFreeRange (0, 1, FirstFreeLCN);

            for (i = 0; i < Drive->GetDBFileCount(); i++)
            {
                FileInfo Info;
                bool Result;
                uint64 TargetLCN;

                wprintf (L"\r");

                Info = Drive->GetDBFile (i);

                FitName (PrintName, Drive->GetDBDir (Info.DirIndice).c_str(), Info.Name.c_str(), Width);
                wprintf (L"    %6.2f%% %-66s", (float)i / (float)Drive->GetDBFileCount() * 100.0f, PrintName);

                // Can't defrag 0 byte files :)
                if (Info.Fragments.size() == 0)
                    continue;

                // If doing fast defrag, skip non-fragmented files
                if (Info.Fragments.size() == 1  &&  DefragMode == DefragFast)
                    continue;

                // Find a place that can fit the file
                Result = Drive->FindFreeRange (FirstFreeLCN, Info.Clusters, TargetLCN);

                // If we're doing an extensive defrag and the file is already defragmented
                // and if its new location would be after its current location, don't
                // move it.
                if (DefragMode == DefragExtensive  &&  Info.Fragments.size() == 1)
                {
                    if (TargetLCN > Info.Fragments[0].StartLCN)
                        continue;
                }

                // Otherwise, defrag0rize it!
                if (Result)
                {
                    bool Success = false;

                    if (Drive->MoveFileDumb (i, TargetLCN))
                        Success = true;
                    else
                    {   // hmm, look for another area to move it to
                        Result = Drive->FindFreeRange (TargetLCN + 1, Info.Clusters, TargetLCN);
                        if (Result)
                        {
                            if (Drive->MoveFileDumb (i, TargetLCN))
                                Success = true;
                            else
                            {   // Try updating the drive bitmap
                                if (Drive->GetBitmap ())
                                {
                                    Result = Drive->FindFreeRange (0, Info.Clusters, TargetLCN);
                                    if (Result)
                                    {
                                        if (Drive->MoveFileDumb (i, TargetLCN))
                                            Success = true;
                                    }
                                }
                            }
                        }
                    }

                    if (!Success)
                        wprintf (L"\n        -> failed\n");

                    Drive->FindFreeRange (0, 1, FirstFreeLCN);
                }
            }

            wprintf (L"\n");
        }
        wprintf (L"Closing volume %s ...", Drives[d].c_str());
        delete Drive;
        wprintf (L"\n");
    }
#endif

    return (0);
}
Пример #11
0
void PLWEMFDecoder::Open (PLDataSource * pDataSrc)
{
	PLASSERT_VALID(this);
  PLASSERT(m_bm == 0);
  PLASSERT(m_memdc == 0);
  PLASSERT(m_hemf == 0);

	SAPMFILEHEADER* pplaceablehdr = NULL;
	bool isadobe = false;
      bool isemf = false;

	// Get the type of the file (WMF or EMF) from the file name
      if (pDataSrc->NameIsWide()){
        wchar_t* strname = wcsdup(pDataSrc->GetNameW());
        PLASSERT(strname);
        if (strname == NULL) {
                // This should never happen under 32-Bit, but who knows?
                PLASSERT(false);
                raiseError (PL_ERRNO_MEMORY,"Out of memory during strdup.");
        }
        wcsupr(strname);
        isemf = wcsstr(strname,L".EMF") != NULL;
        free(strname);
      }
      else{
	char* strname = strdup(pDataSrc->GetName());
	PLASSERT(strname);
	if (strname == NULL) {
		// This should never happen under 32-Bit, but who knows?
		PLASSERT(false);
		raiseError (PL_ERRNO_MEMORY,"Out of memory during strdup.");
	}
	strupr(strname);
	isemf = strstr(strname,".EMF") != NULL;
	free(strname);
      }

	// Get a DC for the display
	m_dc = ::GetDC(NULL);
	PLASSERT(m_dc);
	if (m_dc == NULL) {
		PLASSERT(false);
		raiseError (PL_ERRNO_MEMORY,"Cannot allocate device context.");
	}

	if (isemf) {
		// We have an enhanced meta file which makes it alot easier
		m_hemf = SetEnhMetaFileBits(pDataSrc->GetFileSize(),pDataSrc->ReadEverything());
	}
	else {
		// Buh, old 16-Bit WMF, Convert it to an enhanced metafile before proceeding.
		// Also, check if this is a placeable metafile with an Adobe Placeable header
		pplaceablehdr = (SAPMFILEHEADER*)pDataSrc->ReadEverything();
		PLBYTE* p = NULL;
		UINT size;
		// If we have an adobe header, skip it to use only the real windows-conform data
		if (pplaceablehdr->key == ALDUSKEY) {
			isadobe = true;
			p = pDataSrc->ReadEverything()+sizeof(SAPMFILEHEADER);
			size = pDataSrc->GetFileSize() - sizeof(SAPMFILEHEADER);
		}
		else {
			// Else use the whole file contents as the metafile and assume
			// a native 16-Bit Windows-conform WMF
			p = pDataSrc->ReadEverything();
			size = pDataSrc->GetFileSize();
		}
		#ifdef _MFC_VER
		PLASSERT(AfxIsValidAddress(p,size,false));
		#endif
		m_hemf = SetWinMetaFileBits(size,p,m_dc,NULL);
	}

	// If m_hemf is NULL, windows refused to load the metafile. If this is
	// the case, we're done. Notify the caller
	if (m_hemf == NULL) {
		raiseError (PL_ERRFORMAT_NOT_SUPPORTED,"Windows Metafile functions failed to load this image.");
	}

	// Get the header from the enhanced metafile, It contains some
	// useful information which will aid us during constuction of
	// the bitmap.
	// The header is of variable length. First get the amount of
	//  memory required for the header
	UINT sizeneeded = GetEnhMetaFileHeader(m_hemf,0,NULL);
	if (sizeneeded == 0) {
		raiseError (PL_ERRFORMAT_UNKNOWN,"No header information in metafile");
	}

	// Allocate storage for the header and read it in
	m_phdr = (LPENHMETAHEADER) new PLBYTE[sizeneeded];
	if (m_phdr == NULL) {
		PLASSERT(false);
		raiseError (PL_ERRNO_MEMORY,"Out of memory during allocation of header.");
	}
	m_phdr->iType = EMR_HEADER;
	m_phdr->nSize = sizeneeded;
	#ifdef _MFC_VER
	PLASSERT(AfxIsValidAddress(m_phdr,sizeneeded,true));
	#endif
	GetEnhMetaFileHeader(m_hemf,sizeneeded,m_phdr);

	/*int bpp =*/ GetDeviceCaps(m_dc,BITSPIXEL);

	// Calculate the dimensions of the final bitmap. If we have
	// a placeable header in the WMF, we use the dimensions of
	// that image, else we use the calculated dimensions in the
	// EMF
	int width,height;
	if (isadobe) {
		PLASSERT(pplaceablehdr);
		int lpx = GetDeviceCaps(m_dc,LOGPIXELSX);
		int lpy = GetDeviceCaps(m_dc,LOGPIXELSY);
		// Calculate the absolute with and height and transform from twips to pixel
		width  = (int) (pplaceablehdr->Right-pplaceablehdr->Left) * lpx / pplaceablehdr->inch;
		height = (int) (pplaceablehdr->Bottom-pplaceablehdr->Top) * lpy / pplaceablehdr->inch;
	}
	else {
		// Use the rclFrame of the header because it is the true device independent
		// information and also some applications (e.g. Corel) don't fill the
		// rclBounds correctly
		// Using:
		//     MetaPixelsX = MetaWidthMM * MetaPixels / (MetaMM * 100);
		// where:
		//     MetaWidthMM = metafile width in 0.01mm units
		//     MetaPixels  = width in pixels of the reference device
		//     MetaMM      = width in millimeters of the reference device
		// Same applies to the Y axis
		width  = ((m_phdr->rclFrame.right  - m_phdr->rclFrame.left) * m_phdr->szlDevice.cx) / (m_phdr->szlMillimeters.cx*100);
		height = ((m_phdr->rclFrame.bottom  - m_phdr->rclFrame.top) * m_phdr->szlDevice.cy) / (m_phdr->szlMillimeters.cy*100);
	}

	// If this is a very old WMF without a PLACEABLE info,
	// we use somewhat meaningful defaults. Also, if the header was
	// not written correctly, we use this as a fallback
	if (width <= 0) {
		width = 320;
	}
	if (height <= 0) {
		height = 200;
	}

	// Create a device content for the screen, and a memory device
	// content to play the metafile to

	m_memdc = CreateCompatibleDC(m_dc);
	PLASSERT(m_memdc);
	if (m_memdc == NULL) {
		PLASSERT(false);
		raiseError (PL_ERRNO_MEMORY,"Cannot allocate device context.");
	}

	m_bm = CreateCompatibleBitmap(m_dc,width,height);
	if (m_bm == NULL) {
		PLASSERT(false);
		raiseError (PL_ERRNO_MEMORY,"Cannot allocate memory bitmap.");
	}

	m_holdbm = SelectObject(m_memdc,m_bm);

	// If the metafile has a palette, read it in
	UINT pe = GetEnhMetaFilePaletteEntries(m_hemf, 0, NULL);

	// pe is the real number of palette entries. To make the resulting
	// bitmap more useful, we always setup a 256 color palette if the
	// metafile has a palette
  if (pe>0 && pe<256)
  {
    SetBmpInfo (PLPoint (width, height), PLPoint(0,0), 
             PLPixelFormat::L8);
	}
	else 
  {
    SetBmpInfo (PLPoint (width, height), PLPoint(0,0), 
            PLPixelFormat::B8G8R8A8);
  }
}
void Button_Panel::SetButtonText(const char* Text)
{
	ButtonText = GetGameUI2().ConvertToLocalizedString(Text);
	ButtonText = wcsupr(ButtonText);
}
Пример #13
0
void CDlgFileAssoc::ExtAssignDyn(LPWSTR extName, LPWSTR extCmd, int iconIndex) {

	HKEY hKey;
	DWORD len = 100;
	wchar_t buf[100];

	wchar_t szKeyUpr[20];
	wchar_t szKeyName[20];
	wchar_t szKeyDesc[50];
	wchar_t szKeyStr[50];

	wcscpy(szKeyUpr, extName);
	wcsupr(szKeyUpr);

	wsprintf(szKeyName, L".%s", extName);
	wsprintf(szKeyStr, L"%s file", szKeyUpr);
	wsprintf(szKeyDesc, L"Nitrogen%sFile", szKeyUpr);

	RegCreateKeyExW(HKEY_CLASSES_ROOT, szKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hKey, NULL);

	if (RegQueryValueExW(hKey, NULL, NULL, NULL, (BYTE*)buf, &len) == ERROR_SUCCESS) {
		if (len > 0) {
			RegSetValueExW(hKey, L"Nitrogen backup", 0, REG_SZ, (BYTE*)buf, len);
		}
	}
	
	RegSetValueExW(hKey, NULL, 0, REG_SZ, (BYTE*)szKeyDesc, wcslen(szKeyDesc)*2+2);

	wchar_t oldSettings[100];
	oldSettings[0] = 0;
	len = 100;

	if (RegQueryValueExW(hKey, L"Nitrogen backup", NULL, NULL, (BYTE*)buf, &len) == ERROR_SUCCESS) {
		wcscpy(oldSettings, buf);
	}

	RegCloseKey(hKey);

	RegCreateKeyExW(HKEY_CLASSES_ROOT, szKeyDesc, 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hKey, NULL);
	RegSetValueExW(hKey, NULL, 0, REG_SZ, (BYTE*)szKeyStr, wcslen(szKeyStr)*2+2);
	RegCloseKey(hKey);

	wchar_t sIco[100];
	wsprintf(sIco, L"%s\\DefaultIcon", szKeyDesc);
	RegCreateKeyExW(HKEY_CLASSES_ROOT, sIco, 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hKey, NULL);
	wchar_t s[MAX_PATH];
	wsprintf(s, L"%sNitrogen.exe,%i", player()->Path, iconIndex);
	RegSetValueExW(hKey, NULL, 0, REG_SZ, (BYTE*)s, wcslen(s)*2+2);
	RegCloseKey(hKey);

	wchar_t sCmd[100];
	wsprintf(sCmd, L"%s\\Shell\\Open\\Command", szKeyDesc);
	RegCreateKeyExW(HKEY_CLASSES_ROOT, sCmd, 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hKey, NULL);
	wsprintf(s, L"\"%sNitrogen.exe\" %s", player()->Path, extCmd);
	RegSetValueExW(hKey, NULL, 0, REG_SZ, (BYTE*)s, wcslen(s)*2+2);
	RegCloseKey(hKey);

	if (oldSettings[0] != 0) {
		HKEY hKeyIn;
		wchar_t PathShellExIn[MAX_PATH];
		wsprintf(PathShellExIn, L"%s\\ShellEx", oldSettings);
		if (RegOpenKeyExW(HKEY_CLASSES_ROOT, PathShellExIn, 0, 0, &hKeyIn) == ERROR_SUCCESS) {
			wchar_t PathShellExOut[MAX_PATH];
			wsprintf(PathShellExOut, L"%s\\ShellEx", szKeyDesc);
			HKEY hKeyOut;
			if (RegCreateKeyExW(HKEY_CLASSES_ROOT, PathShellExOut, 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hKeyOut, NULL) == ERROR_SUCCESS) {
				RegCopyData(hKeyIn, hKeyOut);
				RegCloseKey(hKeyOut);
			}
			RegCloseKey(hKeyIn);
		}
	}
}