Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Simple Linux launcher for Windows software, great if you want a simple double-clickable exe that just
- runs windows software emulated through wine. It's not perfect, I did it just to practice some new things I learnt.
- Written to work with Derive, but it can work with other software too, just write the 'launcherconfig' xml file accordingly
- e.g.:
- <?xml version="1.0" encoding="utf-8"?>
- <properties>
- <property name="path">~/Dropbox/SW\ utile/Derive\ 6/</property>
- <property name="exe">Derive6.exe</property>
- <property name="emu">wine</property>
- </properties>
- Requires Mini-XML (http://www.minixml.org/) and wine.
- Compiles with the following command:
- gcc -o myprogram derivel.c -lmxml -lpthread -o launcher
- Run with double click or:
- ./launcher
- */
- #include <stdio.h>
- #include <string.h>
- #include <mxml.h>
- int main()
- {
- //Valore di return
- int ret=0;
- //Creo l'albero dell'XML
- FILE* config = fopen("launcherconfig", "r");
- if(!config)
- {
- printf(
- "Manca un file di configurazione chiamato 'launcherconfig' nella cartella corrente.\
- \nIl file e' del tipo:\n\
- \n<?xml version=\"1.0\" encoding=\"utf-8\"?>\
- \n<properties>\
- \n\t<property name=\"path\"> path della directory contenente Derive </property>\
- \n\t<property name=\"exe\"> nome dell'eseguibile di Derive </property>\
- \n\t<property name=\"emu\"> wine o altro comando per l'emulazione di eseguibili Windows </property>\
- \n</properties>\n\
- \nCreare tale file e riprovare.\n");
- ret=1;
- }
- else
- {
- mxml_node_t* tree = mxmlLoadFile(NULL, config, MXML_OPAQUE_CALLBACK); //La callback opaque mi consente di tenere conto dei whitespace nei valori dell'XML
- fclose(config);
- //Recupero i valori dall'XML
- mxml_node_t *emuNode = mxmlFindElement(tree, tree, "property", "name", "emu", MXML_DESCEND);
- mxml_node_t *pathNode = mxmlFindElement(tree, tree, "property", "name", "path", MXML_DESCEND);
- mxml_node_t *exeNode = mxmlFindElement(tree, tree, "property", "name", "exe", MXML_DESCEND);
- char* emuname = mxmlGetOpaque(emuNode);
- char* pathdir = mxmlGetOpaque(pathNode);
- char* exename = mxmlGetOpaque(exeNode);
- char* command = NULL;
- asprintf(&command, "$(%s %s%s)>/dev/null 2>&1", emuname, pathdir, exename);
- //printf("comando eseguito:%s\n", command);
- //Chiamo il comando
- ret = system(command);
- //Libero la memoria
- free(command);
- mxmlDelete(tree);
- }
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement