From 6ac508a5de77ad8ec7cdba374ad4731d1ee2665a Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Wed, 6 Apr 2011 18:12:05 +0100 Subject: [PATCH] Start register_extension support for linux Also fix a limitation on the length of open: paths --- src/main.c | 4 ++-- src/misc.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index c1be09ffd..181c84f36 100644 --- a/src/main.c +++ b/src/main.c @@ -2236,8 +2236,8 @@ int main(int argc, char *argv[]) { int size; void *file_data; - char fn[64]; - strncpy(fn, argv[i]+5, strlen(argv[i]+5)); + char *fn = malloc(strlen(argv[i]+5)+1); + strcpy(fn, argv[i]+5); file_data = file_load(fn, &size); if (file_data) { diff --git a/src/misc.c b/src/misc.c index 3b147bd3f..78f7ffd07 100644 --- a/src/misc.c +++ b/src/misc.c @@ -10,6 +10,8 @@ #include "powder.h" #if defined WIN32 #include +#else +#include #endif #ifdef MACOSX #include @@ -487,10 +489,47 @@ int register_extension() RegCloseKey(newkey); return 1; -#elif defined LIN32 - return 0; -#elif defined LIN64 - return 0; +#elif defined(LIN32) || defined(LIN64) + char *currentfilename = exe_name(); + FILE *f; + char *mimedata = +"\n" +" \n" +" \n" +" Powder Toy save\n" +" \n" +" \n" +" \n" +"\n"; + f = fopen("powdertoy-save.xml", "wb"); + if (!f) + return 0; + fwrite(mimedata, 1, strlen(mimedata), f); + fclose(f); + + char *desktopfiledata_tmp = +"[Desktop Entry]\n" +"Type=Application\n" +"Name=Powder Toy\n" +"Comment=Physics sandbox game\n" +"MimeType=application/vnd.powdertoy.save;\n" +"NoDisplay=true\n"; + char *desktopfiledata = malloc(strlen(desktopfiledata_tmp)+strlen(currentfilename)+100); + strcpy(desktopfiledata, desktopfiledata_tmp); + strappend(desktopfiledata, "Exec="); + strappend(desktopfiledata, currentfilename); + strappend(desktopfiledata, " open:%f\n"); + f = fopen("powdertoy-tpt.desktop", "wb"); + if (!f) + return 0; + fwrite(desktopfiledata, 1, strlen(desktopfiledata), f); + fclose(f); + system("xdg-mime install powdertoy-save.xml"); + system("xdg-desktop-menu install powdertoy-tpt.desktop"); + // TODO: icons + unlink("powdertoy-save.xml"); + unlink("powdertoy-tpt.desktop"); + return 1; #elif defined MACOSX return 0; #endif