Advertisement
Frash

Wine launcher

Feb 22nd, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.42 KB | None | 0 0
  1. /*
  2.     Simple Linux launcher for Windows software, great if you want a simple double-clickable exe that just
  3.     runs windows software emulated through wine. It's not perfect, I did it just to practice some new things I learnt.
  4.     Written to work with Derive, but it can work with other software too, just write the 'launcherconfig' xml file accordingly
  5.     e.g.:
  6.    
  7.     <?xml version="1.0" encoding="utf-8"?>
  8.     <properties>
  9.         <property name="path">~/Dropbox/SW\ utile/Derive\ 6/</property>
  10.         <property name="exe">Derive6.exe</property>
  11.         <property name="emu">wine</property>
  12.     </properties>
  13.    
  14.     Requires Mini-XML (http://www.minixml.org/) and wine.
  15.    
  16.     Compiles with the following command:
  17.     gcc -o myprogram derivel.c -lmxml -lpthread -o launcher
  18.    
  19.     Run with double click or:
  20.     ./launcher
  21. */
  22.  
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <mxml.h>
  26.  
  27. int main()
  28. {
  29.     //Valore di return
  30.     int ret=0;
  31.    
  32.     //Creo l'albero dell'XML
  33.     FILE* config = fopen("launcherconfig", "r");
  34.     if(!config)
  35.     {
  36.         printf(
  37.         "Manca un file di configurazione chiamato 'launcherconfig' nella cartella corrente.\
  38.         \nIl file e' del tipo:\n\
  39.         \n<?xml version=\"1.0\" encoding=\"utf-8\"?>\
  40.         \n<properties>\
  41.         \n\t<property name=\"path\"> path della directory contenente Derive </property>\
  42.         \n\t<property name=\"exe\"> nome dell'eseguibile di Derive </property>\
  43.         \n\t<property name=\"emu\"> wine o altro comando per l'emulazione di eseguibili Windows </property>\
  44.         \n</properties>\n\
  45.         \nCreare tale file e riprovare.\n");
  46.         ret=1;
  47.     }
  48.     else
  49.     {
  50.         mxml_node_t* tree = mxmlLoadFile(NULL, config, MXML_OPAQUE_CALLBACK); //La callback opaque mi consente di tenere conto dei whitespace nei valori dell'XML
  51.         fclose(config);
  52.    
  53.         //Recupero i valori dall'XML
  54.    
  55.         mxml_node_t *emuNode = mxmlFindElement(tree, tree, "property", "name", "emu", MXML_DESCEND);
  56.         mxml_node_t *pathNode = mxmlFindElement(tree, tree, "property", "name", "path", MXML_DESCEND);
  57.         mxml_node_t *exeNode = mxmlFindElement(tree, tree, "property", "name", "exe", MXML_DESCEND);
  58.    
  59.         char* emuname = mxmlGetOpaque(emuNode);
  60.         char* pathdir = mxmlGetOpaque(pathNode);
  61.         char* exename = mxmlGetOpaque(exeNode);
  62.    
  63.         char* command = NULL;
  64.         asprintf(&command, "$(%s %s%s)>/dev/null 2>&1", emuname, pathdir, exename);
  65.        
  66.         //printf("comando eseguito:%s\n", command);
  67.    
  68.    
  69.         //Chiamo il comando
  70.         ret = system(command);
  71.    
  72.         //Libero la memoria
  73.         free(command);
  74.         mxmlDelete(tree);
  75.     }
  76.     return ret;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement