shellext.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "stdAfx.h"
  19. #include "priv.h"
  20. #include "Chunkio.h"
  21. #include "io.h"
  22. #include "wdump.h"
  23. #include "WdumpDoc.h"
  24. //#include "w3d2dat.h" /// LFeenanEA: Header file missing, perhaps this tool is outdated?
  25. //
  26. // Initialize GUIDs (should be done only and at-least once per DLL/EXE)
  27. //
  28. #pragma data_seg(".text")
  29. #define INITGUID
  30. #include <initguid.h>
  31. #include <shlguid.h>
  32. #include "shellext.h"
  33. #pragma data_seg()
  34. // Global variables
  35. //
  36. UINT g_DllRefCount = 0; // Reference count of this DLL.
  37. HINSTANCE g_DllInstance = NULL; // Handle to this DLL itself.
  38. //===============================================================
  39. extern "C" int APIENTRY
  40. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved){
  41. if (dwReason == DLL_PROCESS_ATTACH){
  42. g_DllInstance = hInstance;
  43. }else
  44. if (dwReason == DLL_PROCESS_DETACH){
  45. ODS3("Detaching Process");
  46. }
  47. return 1; // ok
  48. }
  49. //---------------------------------------------------------------------------
  50. // DllCanUnloadNow
  51. //---------------------------------------------------------------------------
  52. STDAPI DllCanUnloadNow(void)
  53. {
  54. return (g_DllRefCount == 0 ? S_OK : S_FALSE);
  55. }
  56. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut)
  57. {
  58. *ppvOut = NULL;
  59. if (IsEqualIID(rclsid, CLSID_ShellExtension)) {
  60. CShellExtClassFactory* pcf = new CShellExtClassFactory;
  61. return pcf->QueryInterface(riid, ppvOut);
  62. }
  63. return CLASS_E_CLASSNOTAVAILABLE;
  64. }
  65. //======================================================================================
  66. CShellExtClassFactory::CShellExtClassFactory()
  67. {
  68. m_cRef = 0L;
  69. g_DllRefCount++;
  70. }
  71. //======================================================================================
  72. CShellExtClassFactory::~CShellExtClassFactory(){
  73. g_DllRefCount--;
  74. }
  75. //======================================================================================
  76. STDMETHODIMP CShellExtClassFactory::QueryInterface(REFIID riid, LPVOID FAR *ppv){
  77. *ppv = NULL;
  78. // Any interface on this object is the object pointer
  79. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory)){
  80. *ppv = (LPCLASSFACTORY)this;
  81. AddRef();
  82. return NOERROR;
  83. }
  84. return E_NOINTERFACE;
  85. }
  86. //======================================================================================
  87. STDMETHODIMP_(ULONG) CShellExtClassFactory::AddRef()
  88. {
  89. return ++m_cRef;
  90. }
  91. STDMETHODIMP_(ULONG) CShellExtClassFactory::Release()
  92. {
  93. if (--m_cRef)
  94. return m_cRef;
  95. delete this;
  96. return 0L;
  97. }
  98. STDMETHODIMP CShellExtClassFactory::CreateInstance(LPUNKNOWN pUnkOuter,REFIID riid,LPVOID *ppvObj){
  99. *ppvObj = NULL;
  100. // Shell extensions typically don't support aggregation (inheritance)
  101. if (pUnkOuter)
  102. return CLASS_E_NOAGGREGATION;
  103. // Create the main shell extension object. The shell will then call
  104. // QueryInterface with IID_IShellExtInit--this is how shell extensions are
  105. // initialized.
  106. LPCSHELLEXT pShellExt = new CShellExt(); //Create the CShellExt object
  107. if (NULL == pShellExt)
  108. return E_OUTOFMEMORY;
  109. return pShellExt->QueryInterface(riid, ppvObj);
  110. }
  111. STDMETHODIMP CShellExtClassFactory::LockServer(BOOL fLock)
  112. {
  113. return NOERROR;
  114. }
  115. // *********************** CShellExt *************************
  116. CShellExt::CShellExt(): m_FileInMemory(false),
  117. m_NumAdded(0),
  118. m_FoundMeshes(0){
  119. m_cRef = 0L;
  120. m_pDataObj = NULL;
  121. g_DllRefCount++;
  122. }
  123. CShellExt::~CShellExt()
  124. {
  125. if (m_pDataObj)
  126. m_pDataObj->Release();
  127. g_DllRefCount--;
  128. }
  129. STDMETHODIMP CShellExt::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  130. {
  131. *ppv = NULL;
  132. if (IsEqualIID(riid, IID_IShellExtInit) || IsEqualIID(riid, IID_IUnknown)) {
  133. *ppv = (LPSHELLEXTINIT)this;
  134. }else {
  135. if (IsEqualIID(riid, IID_IContextMenu)) {
  136. *ppv = (LPCONTEXTMENU)this;
  137. }else{
  138. if (IsEqualIID(riid, IID_IExtractIcon)){
  139. *ppv = (LPEXTRACTICON)this;
  140. }else {
  141. if (IsEqualIID(riid, IID_IPersistFile)){
  142. *ppv = (LPPERSISTFILE)this;
  143. }else {
  144. if (IsEqualIID(riid, IID_IShellPropSheetExt)){
  145. *ppv = (LPSHELLPROPSHEETEXT)this;
  146. }else {
  147. if (IsEqualIID(riid, IID_IShellCopyHook)){
  148. *ppv = (LPCOPYHOOK)this;
  149. }
  150. }
  151. }
  152. }
  153. }
  154. }
  155. if (*ppv){
  156. AddRef();
  157. return NOERROR;
  158. }
  159. return E_NOINTERFACE;
  160. }
  161. STDMETHODIMP_(ULONG) CShellExt::AddRef()
  162. {
  163. return ++m_cRef;
  164. }
  165. STDMETHODIMP_(ULONG) CShellExt::Release()
  166. {
  167. if (--m_cRef){
  168. return m_cRef;
  169. }
  170. delete this;
  171. return 0L;
  172. }
  173. void CShellExt::Read_SelectedFile(){
  174. m_WdumpDocument.Read_File(m_SelectedFile);
  175. m_FileInMemory = true;
  176. }
  177. bool CShellExt::NotAdded(char* name){
  178. CString str = name;
  179. for(int pos(0); pos < m_NumAdded; pos ++){
  180. if(str == m_Textures[pos]){
  181. return false;
  182. }
  183. }
  184. m_Textures[m_NumAdded ++ ] = str;
  185. return true;
  186. }
  187. /////////////////////////////////////////////////////////////