Просмотр исходного кода

Added icons to IDE and the player in windows. Made the IDE create file associations for the IDE and the player on launch. Made the IDE a single instance applications and implemented opening files in the running instance. Added (hacky) support for WM_COPYDATA string passing in Windows core.

Ivan Safrin 12 лет назад
Родитель
Сommit
838f415b7a

BIN
Assets/Icons/app_file_icon.ico


BIN
Assets/Icons/main_icon.ico


BIN
Assets/Icons/player_icon.ico


BIN
Assets/Icons/polycode_project.ico


+ 2 - 0
Core/Contents/Include/PolyWinCore.h

@@ -248,6 +248,8 @@ public:
 		std::vector<GamepadDeviceEntry*> gamepads;
 
 		HWND hWnd;
+		bool hasCopyDataString;
+		String copyDataString;
 
 	private:
 

+ 8 - 0
Core/Contents/PolycodeView/MSVC/PolycodeView.cpp

@@ -53,6 +53,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 
 	switch (message)
 	{
+	case WM_COPYDATA:
+	{
+		COPYDATASTRUCT *cp = (COPYDATASTRUCT*)lParam;
+		wchar_t *stringData = (wchar_t*)cp->lpData;
+		core->copyDataString = String(stringData);
+		core->hasCopyDataString = true;
+	}
+	break;
 	case WM_SIZE:
 		nWidth = LOWORD(lParam); 
 		nHeight = HIWORD(lParam);

+ 1 - 0
Core/Contents/Source/PolyWinCore.cpp

@@ -83,6 +83,7 @@ Win32Core::Win32Core(PolycodeViewBase *view, int _xRes, int _yRes, bool fullScre
 
 	hWnd = *((HWND*)view->windowData);
 	core = this;
+	hasCopyDataString = false;
 
 	char *buffer = _getcwd(NULL, 0);
 	defaultWorkingDirectory = String(buffer);

+ 3 - 3
IDE/Build/Windows/Polycode.props

@@ -5,10 +5,10 @@
     <PolycodeDir>$(SolutionDir)..\..\..\Release\Windows\Framework\</PolycodeDir>
     <PolycodeCoreLibsDebug>Polycore_d.lib</PolycodeCoreLibsDebug>
     <PolycodeCoreLibsRelease>Polycore.lib</PolycodeCoreLibsRelease>
-    <PolycodeDependLibsDebug>PolycodeUI_d.lib;Polycore_d.lib;zlibd.lib;freetype_d.lib;liboggd.lib;libvorbisd.lib;libvorbisfiled.lib;OpenAL32d.lib;physfsd.lib;libpng15_staticd.lib</PolycodeDependLibsDebug>
+    <PolycodeDependLibsDebug>PolycodeUI_d.lib;Polycore_d.lib;zlibd.lib;freetype_d.lib;liboggd.lib;libvorbisd.lib;libvorbisfiled.lib;OpenAL32d.lib;physfsd.lib;libpng15_staticd.lib;</PolycodeDependLibsDebug>
     <PolycodeDependLibsRelease>PolycodeUI.lib;Polycore.lib;zlib.lib;freetype.lib;libogg.lib;libvorbis.lib;libvorbisfile.lib;OpenAL32.lib;physfs.lib;libpng15_static.lib</PolycodeDependLibsRelease>
-    <PolycodeWinLibsDebug>opengl32.lib;glu32.lib;winmm.lib;ws2_32.lib</PolycodeWinLibsDebug>
-    <PolycodeWinLibsRelease>opengl32.lib;glu32.lib;winmm.lib;ws2_32.lib</PolycodeWinLibsRelease>
+    <PolycodeWinLibsDebug>opengl32.lib;glu32.lib;winmm.lib;ws2_32.lib;Shlwapi.lib</PolycodeWinLibsDebug>
+    <PolycodeWinLibsRelease>opengl32.lib;glu32.lib;winmm.lib;ws2_32.lib;Shlwapi.lib</PolycodeWinLibsRelease>
     <PolycodeLibsDebug>$(PolycodeCoreLibsDebug);$(PolycodeDependLibsDebug);$(PolycodeWinLibsDebug)</PolycodeLibsDebug>
     <PolycodeLibsRelease>$(PolycodeCoreLibsRelease);$(PolycodeDependLibsRelease);$(PolycodeWinLibsRelease)</PolycodeLibsRelease>
   </PropertyGroup>

+ 6 - 1
IDE/Build/Windows/Polycode.sln

@@ -1,8 +1,13 @@
 
 Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual C++ Express 2010
+# Visual Studio 2010
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Polycode", "Polycode.vcxproj", "{D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}"
 EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0D5CDD59-CFF6-4143-8D1D-A92BBAB86060}"
+	ProjectSection(SolutionItems) = preProject
+		Performance1.psess = Performance1.psess
+	EndProjectSection
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Win32 = Debug|Win32

+ 10 - 0
IDE/Build/Windows/Polycode.vcxproj

@@ -67,6 +67,16 @@
     <ClInclude Include="..\..\Contents\Include\SettingsWindow.h" />
     <ClInclude Include="..\..\Contents\Include\TextureBrowser.h" />
     <ClInclude Include="..\..\Contents\Include\ToolWindows.h" />
+    <ClInclude Include="resource.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="Polycode.rc" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="..\..\..\Assets\Icons\app_file_icon.ico" />
+    <None Include="..\..\..\Assets\Icons\main_icon.ico" />
+    <None Include="..\..\..\Assets\Icons\main_icon.png" />
+    <None Include="..\..\..\Assets\Icons\polycode_project.ico" />
   </ItemGroup>
   <PropertyGroup Label="Globals">
     <ProjectGuid>{D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}</ProjectGuid>

+ 10 - 0
IDE/Build/Windows/Polycode.vcxproj.filters

@@ -173,5 +173,15 @@
     <ClInclude Include="..\..\Contents\Include\SettingsWindow.h">
       <Filter>Include</Filter>
     </ClInclude>
+    <ClInclude Include="resource.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="Polycode.rc" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="..\..\..\Assets\Icons\main_icon.png" />
+    <None Include="..\..\..\Assets\Icons\main_icon.ico" />
+    <None Include="..\..\..\Assets\Icons\polycode_project.ico" />
+    <None Include="..\..\..\Assets\Icons\app_file_icon.ico" />
   </ItemGroup>
 </Project>

+ 80 - 0
IDE/Build/Windows/main.cpp

@@ -2,20 +2,100 @@
 #include "PolycodeIDEApp.h"
 #include "PolycodeView.h"
 #include "windows.h"
+#include "resource.h"
+#include <Shlobj.h>
+#include <Shlwapi.h>
+#include <shellapi.h>
 
 using namespace Polycode;
 
+void registerFileType(String extension, String progId, String app, String defaultIcon, String desc) {
+	HKEY hkey;
+
+	RegCreateKeyEx(HKEY_CLASSES_ROOT,extension.getWDataWithEncoding(String::ENCODING_UTF8),0,0,0,KEY_ALL_ACCESS,0,&hkey,0);
+	RegSetValueEx(hkey,L"",0,REG_SZ,(BYTE*)progId.getWDataWithEncoding(String::ENCODING_UTF8),progId.length() * sizeof(wchar_t));
+	RegCloseKey(hkey);
+
+	RegCreateKeyEx(HKEY_CLASSES_ROOT,L".polyproject\\OpenWithProgIds\\",0,0,0,KEY_ALL_ACCESS,0,&hkey,0);
+	RegSetValueEx(hkey,progId.getWDataWithEncoding(String::ENCODING_UTF8),0,REG_NONE,0,0);
+	RegCloseKey(hkey);
+
+	RegCreateKeyEx(HKEY_CLASSES_ROOT,progId.getWDataWithEncoding(String::ENCODING_UTF8),0,0,0,KEY_ALL_ACCESS,0,&hkey,0);
+	RegSetValueEx(hkey,L"",0,REG_SZ,(BYTE*)desc.getWDataWithEncoding(String::ENCODING_UTF8),desc.length() * sizeof(wchar_t));
+	RegCloseKey(hkey);
+
+	String path = progId + "\\shell\\open\\command\\";
+	RegCreateKeyEx(HKEY_CLASSES_ROOT,path.getWDataWithEncoding(String::ENCODING_UTF8),0,0,0,KEY_ALL_ACCESS,0,&hkey,0);
+	RegSetValueEx(hkey,L"",0,REG_SZ,(BYTE*)app.getWDataWithEncoding(String::ENCODING_UTF8),app.length() * sizeof(wchar_t));
+	RegCloseKey(hkey);
+
+	path = progId + "\\DefaultIcon\\";
+	RegCreateKeyEx(HKEY_CLASSES_ROOT,path.getWDataWithEncoding(String::ENCODING_UTF8),0,0,0,KEY_ALL_ACCESS,0,&hkey,0);
+	RegSetValueEx(hkey,L"",0,REG_SZ,(BYTE*)defaultIcon.getWDataWithEncoding(String::ENCODING_UTF8),defaultIcon.length() * sizeof(wchar_t));
+	RegCloseKey(hkey);
+
+	SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST,0,0);
+
+}
+
 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
 {
+
+	ChangeWindowMessageFilter(WM_COPYDATA,MSGFLT_ADD);
+
+	int nArgs;
+	LPWSTR *szArglist =  CommandLineToArgvW(GetCommandLineW(), &nArgs);
+	
+	String fileName = "";
+	if(nArgs > 1) {
+		fileName = String(szArglist[1]);
+	}
+
+	fileName = fileName.replace("\\", "/");
+
+	// check if an instance of Polycode is running and bring it up and open file if needed
+	HWND runningHwnd = FindWindow(L"POLYCODEAPPLICATION", L"Polycode");
+	if(runningHwnd) {
+		SwitchToThisWindow(runningHwnd, FALSE);
+		ShowWindow(runningHwnd,SW_NORMAL);
+
+		if(fileName != "") {
+			COPYDATASTRUCT cds;
+			cds.cbData = (fileName.length() * sizeof(wchar_t)) + 1;
+			cds.lpData = fileName.getWDataWithEncoding(String::ENCODING_UTF8);
+			SendMessage(runningHwnd, WM_COPYDATA, 0, (LPARAM)&cds);
+		}
+		return 1;
+	}
+
+	TCHAR FilePath[MAX_PATH] = { 0 };
+	GetModuleFileName( 0, FilePath, MAX_PATH );
+	PathRemoveFileSpec( FilePath );    
+	SetCurrentDirectory( FilePath );
+
 	PolycodeView *view = new PolycodeView(hInstance, nCmdShow, L"Polycode", true, false);
 	PolycodeIDEApp *app = new PolycodeIDEApp(view);
 
+	if(fileName != "") {
+		app->openProject(fileName);
+	}
+
+	HICON mainIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
+	SendMessage(view->hwnd, WM_SETICON, ICON_SMALL, (LPARAM) mainIcon );
+
+	registerFileType(".polyproject", "Polycode.ProjectFile.1", CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory()+"\\Polycode.exe \"%1\"", CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory()+"\\Polycode.exe,-103", "Polycode Project");
+	registerFileType(".polyapp", "Polycode.Applicaton.1", CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory()+"\\Standalone\\Player\\PolycodePlayer.exe \"%1\"", CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory()+"\\Polycode.exe,-104", "Polycode Application");
+
 	MSG Msg;
 	do {
 		if(PeekMessage(&Msg, NULL, 0,0,PM_REMOVE)) {
 			TranslateMessage(&Msg);
 			DispatchMessage(&Msg);
 		}
+		if(((Win32Core*)app->core)->hasCopyDataString) {
+			app->openProject(((Win32Core*)app->core)->copyDataString);
+			((Win32Core*)app->core)->hasCopyDataString = false;
+		}
 	} while(app->Update());
 
 	app->saveConfigFile();

+ 5 - 3
Player/Contents/CMakeLists.txt

@@ -31,6 +31,7 @@ SET(polycodeplayer_SRCS
     SET(polycodeplayer_HDRS 
         Include/PolycodePlayer.h
         Include/PolycodeWindowsPlayer.h
+        Include/resource.h
     )
   
     SET(polycodeplayerstandalone_SRCS 
@@ -40,11 +41,12 @@ SET(polycodeplayer_SRCS
     )
     SET(polycodeplayerstandalone_HDRS 
         Include/PolycodePlayer.h
-        Include/PolycodeWindowsPlayer.h   
+        Include/PolycodeWindowsPlayer.h
+        Include/resource.h
     )
  
-    ADD_EXECUTABLE(PolycodePlayer WIN32 ${polycodeplayer_SRCS} ${polycodeplayer_HDRS})
-    ADD_EXECUTABLE(StandalonePlayer WIN32 ${polycodeplayerstandalone_SRCS} ${polycodeplayerstandalone_HDRS})
+    ADD_EXECUTABLE(PolycodePlayer WIN32 Include/Polycode.rc ${polycodeplayer_SRCS} ${polycodeplayer_HDRS})
+    ADD_EXECUTABLE(StandalonePlayer WIN32 Include/Polycode.rc ${polycodeplayerstandalone_SRCS} ${polycodeplayerstandalone_HDRS})
     
 
     TARGET_LINK_LIBRARIES(PolycodePlayer 

BIN
Player/Contents/Include/player_icon.ico


BIN
Player/Contents/Include/resource.h


+ 3 - 0
Player/Contents/Platform/Windows/Standalone/main.cpp

@@ -24,6 +24,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
 	PolycodeView *view = new PolycodeView(hInstance, nCmdShow, L"", false, false);
 	PolycodeWindowsPlayer *player = new PolycodeWindowsPlayer(view, "main.polyapp", false, false);
 
+	HICON mainIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
+	SendMessage(view->hwnd, WM_SETICON, ICON_SMALL, (LPARAM) mainIcon );
+
 	//player->addEventListener(view, PolycodeDebugEvent::EVENT_ERROR);
 	//player->addEventListener(view, PolycodeDebugEvent::EVENT_PRINT);
 

+ 5 - 0
Player/Contents/Platform/Windows/main.cpp

@@ -29,9 +29,14 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
 		fileName = String(szArglist[1]);
 	}
 
+	fileName = fileName.replace("\\", "/");
+
 	PolycodeView *view = new PolycodeView(hInstance, nCmdShow, L"Polycode Player", false, false);
 	PolycodeWindowsPlayer *player = new PolycodeWindowsPlayer(view, fileName.c_str(), false, true);
 
+	HICON mainIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
+	SendMessage(view->hwnd, WM_SETICON, ICON_SMALL, (LPARAM) mainIcon );
+
 //	player->addEventListener(view, PolycodeDebugEvent::EVENT_ERROR);
 //	player->addEventListener(view, PolycodeDebugEvent::EVENT_PRINT);