From c28b2423ccf9b89e4016340ad6a191980ef1da34 Mon Sep 17 00:00:00 2001 From: zeromus Date: Wed, 27 Apr 2011 04:14:38 +0000 Subject: [PATCH] win32: add hicoder patch 3292481 "Windows File Association patch" (its optional) --- desmume/src/NDSSystem.cpp | 5 +- desmume/src/windows/pathsettings.cpp | 109 +++++++++++++++++++++++---- desmume/src/windows/resource.h | 1 + desmume/src/windows/resources.rc | Bin 963606 -> 963814 bytes 4 files changed, 97 insertions(+), 18 deletions(-) diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 37a214de3..666c7fdf3 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -1,5 +1,6 @@ -/* Copyright (C) 2006 yopyop - Copyright (C) 2008-2010 DeSmuME team +/* + Copyright (C) 2006 yopyop + Copyright (C) 2008-2011 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/desmume/src/windows/pathsettings.cpp b/desmume/src/windows/pathsettings.cpp index 904b420d9..d46c3772d 100644 --- a/desmume/src/windows/pathsettings.cpp +++ b/desmume/src/windows/pathsettings.cpp @@ -1,25 +1,24 @@ -/* - Copyright (C) 2007 Hicoder +/* + Copyright (C) 2009-2011 Hicoder, DeSmuME team - This file is part of DeSmuME + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. - DeSmuME is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - DeSmuME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DeSmuME; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + You should have received a copy of the GNU General Public License + along with the this software. If not, see . */ + #include "common.h" #include +#include #include #include #include @@ -32,6 +31,75 @@ case (message): return (SetDlgMsgResult(hDlg, uMsg, \ HANDLE_##message( (hwnd), (wParam), (lParam), (fn) ) ) ) +BOOL associate; +#define ASSOCIATEKEY "Associate" + +void DoAssociations() +{ + string fileTypes[3] = { ".nds", ".ds.gba", ".srl" }; + string program = "Desmume.Emulator"; + string classes = "Software\\Classes"; + string defaultIcon = "DefaultIcon"; + string openVerb = "shell\\open\\command"; + string iconIndex = ", 96"; + string argument = " \"%1\""; + + HKEY user = NULL; + if(RegOpenKeyEx(HKEY_CURRENT_USER, classes.c_str(),0, KEY_ALL_ACCESS, &user) == ERROR_SUCCESS) + { + if(associate) + { + HKEY icon, shell, registered; + if(RegCreateKeyEx(user, program.c_str(), 0, 0, 0, KEY_ALL_ACCESS, NULL, ®istered, 0) == ERROR_SUCCESS) + { + string module; + char buf[MAX_PATH]; + GetModuleFileName(NULL, buf, MAX_PATH); + module.append(buf); + + if(RegCreateKeyEx(registered, defaultIcon.c_str(), 0, 0, 0, KEY_ALL_ACCESS, 0, &icon, 0) == ERROR_SUCCESS) + { + string iconPath = "\""; + iconPath.append(module); + iconPath.append("\""); + iconPath.append(iconIndex); + RegSetValueEx(icon, NULL, 0,REG_SZ, (const BYTE*)iconPath.c_str(), iconPath.size() + 1); + RegCloseKey(icon); + } + + if(RegCreateKeyEx(registered, openVerb.c_str(), 0, 0, 0, KEY_ALL_ACCESS, NULL, &shell, 0) == ERROR_SUCCESS) + { + string openPath = "\""; + openPath.append(module); + openPath.append("\""); + openPath.append(argument); + RegSetValueEx(shell, NULL, 0,REG_SZ, (const BYTE*)openPath.c_str(), openPath.size() + 1); + RegCloseKey(shell); + } + RegCloseKey(registered); + } + + for(int i = 0; i < ARRAY_SIZE(fileTypes); i++) + { + HKEY tmp; + if(RegCreateKeyEx(user, fileTypes[i].c_str(), 0, 0, 0, KEY_ALL_ACCESS, NULL, &tmp, 0) == ERROR_SUCCESS) + { + RegSetValueEx(tmp, NULL, 0,REG_SZ, (const BYTE*)program.c_str(), ARRAY_SIZE(program) + 1); + } + RegCloseKey(tmp); + } + } + else + { + SHDeleteKeyA(user, program.c_str()); + for(int i = 0; i < ARRAY_SIZE(fileTypes); i++) + RegDeleteKey(user, fileTypes[i].c_str()); + } + } + + if(user != NULL) + RegCloseKey(user); +} void WritePathSettings() { @@ -48,6 +116,7 @@ void WritePathSettings() WritePrivateProfileString(SECTION, FORMATKEY, path.screenshotFormat, IniName); WritePrivateProfileInt(SECTION, LASTVISITKEY, path.savelastromvisit, IniName); + WritePrivateProfileInt(SECTION, ASSOCIATEKEY, associate, IniName); // WritePrivateProfileInt(SECTION, DEFAULTFORMATKEY, defaultFormat, IniName); // WritePrivateProfileInt(SECTION, NEEDSSAVINGKEY, needsSaving, IniName); } @@ -67,7 +136,10 @@ BOOL PathSettings_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam) ComboBox_SetCurSel(hwnd, 0);*/ // PathSettings_OnSelChange(hDlg, NULL); + associate = GetPrivateProfileInt(SECTION, ASSOCIATEKEY, 0, IniName); + CheckDlgButton(hDlg, IDC_USELASTVISIT, (path.savelastromvisit) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg, IDC_ASSOCIATE, (associate) ? BST_CHECKED : BST_UNCHECKED); CheckRadioButton(hDlg, IDC_PNG, IDC_BMP, (int)path.imageformat()); // IDC_FORMATEDIT setup @@ -240,7 +312,7 @@ void PathSettings_OnCommand(HWND hDlg, int id, HWND hwndCtl, UINT codeNotify) GetDlgItemText(hDlg, IDC_AVIPATHEDIT, path.pathToAviFiles, MAX_PATH); GetDlgItemText(hDlg, IDC_CHEATPATHEDIT, path.pathToCheats, MAX_PATH); GetDlgItemText(hDlg, IDC_LUAPATHEDIT, path.pathToLua, MAX_PATH); - + DoAssociations(); WritePathSettings(); EndDialog(hDlg, 0); break; @@ -248,9 +320,14 @@ void PathSettings_OnCommand(HWND hDlg, int id, HWND hwndCtl, UINT codeNotify) path.ReadPathSettings(); EndDialog(hDlg, 0); break; + case IDC_ASSOCIATE: + associate = !associate; + break; } } + + LRESULT CALLBACK PathSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) diff --git a/desmume/src/windows/resource.h b/desmume/src/windows/resource.h index 81b3ec84d..8fc39f7f7 100644 --- a/desmume/src/windows/resource.h +++ b/desmume/src/windows/resource.h @@ -145,6 +145,7 @@ #define IDC_LUAPATHEDIT 364 #define IDC_BROWSELUA 365 #define IDD_PATHSETTINGS 366 +#define IDC_ASSOCIATE 367 #define IDC_STATEREWINDING 367 #define IDC_CLOSE_LUA_SCRIPTS 368 #define IDC_DES_BOX 402 diff --git a/desmume/src/windows/resources.rc b/desmume/src/windows/resources.rc index 7985fca211cea0296111de5b007c5c877c85f00c..7336ae7cb85cdf8782e37cc04bc01a3f0387530f 100644 GIT binary patch delta 146 zcmbRC!s^*etA-ZF7N!>F7M3lnSFSN~PXB1grYc#?P|T3ekj#+DkjPNNkjkLIkjIb$ z6jPY~_93gdup>h-5c)GXGk7vMGK4U=GU!Y%v}ZPEteGCD%PY-p#Gu1q#9%&s{!A{( m?Gx^CPhoE_xW@{_Y(NZRa{w_X5OV=BHxTn|FSy6M>?#1Zv@ksY delta 73 zcmaF%(rVfZtA-ZF7N!>F7M3lnSFTNuyUl7aeZoo(j_nifbEmMkJKSdlVm2TKu{nU4 T6NtHhm>Y