~poy/dcpp-plugin-sdk-cpp/Punctuator

« back to all changes in this revision

Viewing changes to packaging/packager/packager.cpp

  • Committer: poy
  • Date: 2013-05-22 19:19:41 UTC
  • Revision ID: poy@123gen.com-20130522191941-rq1j2gyuvybbvr92
generate an info.xml template

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Generate an info.xml template from the version.h file.
 
2
 
 
3
#include <fstream>
 
4
#include <iostream>
 
5
 
 
6
#include <pluginsdk/PluginDefs.h>
 
7
#include <src/version.h>
 
8
 
 
9
using namespace std;
 
10
 
 
11
string escape(string str) {
 
12
        size_t i = 0;
 
13
        while((i = str.find_first_of("<>&", i)) != string::npos) {
 
14
                switch(str[i]) {
 
15
                case '<': str.replace(i, 1, "&lt;"); i += 4; break;
 
16
                case '>': str.replace(i, 1, "&gt;"); i += 4; break;
 
17
                case '&': str.replace(i, 1, "&amp;"); i += 5; break;
 
18
                default: ++i; break;
 
19
                }
 
20
        }
 
21
        return str;
 
22
}
 
23
 
 
24
enum { Path = 1, LastCompulsory = Path };
 
25
 
 
26
int main(int argc, char* argv[]) {
 
27
        if(argc <= LastCompulsory) {
 
28
                cout << "packager: no path given by the build script" << endl;
 
29
                return 1;
 
30
        }
 
31
 
 
32
        ofstream f(argv[Path]);
 
33
        if(!f.is_open()) {
 
34
                cout << "packager: cannot open " << argv[Path] << endl;
 
35
                return 2;
 
36
        }
 
37
 
 
38
        f << "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n\n"
 
39
                "<!--\n"
 
40
                "This file is an example info.xml to be included in the dcext package. For more\n"
 
41
                "information, read \"Plugin format (dcext).txt\" in the \"doc\" directory.\n\n"
 
42
                "This file has been generated using the information filled in the src/version.h file.\n\n"
 
43
                "Edit the <Plugin> tags to include your plugin files.\n"
 
44
                "If you support Windows, include pe-x64 and pe-x86 platforms.\n"
 
45
                "If you support Linux, include elf-x64 and elf-x86 platforms.\n\n"
 
46
                "The <Files> tag is empty; should you want to distribute additional files, include them\n"
 
47
                "in there within <File> tags (again, more information in the above doc file).\n\n"
 
48
                "When you are done editing this file, rename it to \"info.xml\", move the relevant files\n"
 
49
                "to this directory and zip them; rename that .zip to .dcext and you are done!\n"
 
50
                "-->\n\n"
 
51
                "<dcext>\n"
 
52
                "\t<UUID>" << escape(PLUGIN_GUID).c_str() << "</UUID>\n"
 
53
                "\t<Name>" << escape(PLUGIN_NAME).c_str() << "</Name>\n"
 
54
                "\t<Version>" << PLUGIN_VERSION << "</Version>\n"
 
55
                "\t<ApiVersion>" << DCAPI_CORE_VER << "</ApiVersion>\n"
 
56
                "\t<Author>" << escape(PLUGIN_AUTHOR).c_str() << "</Author>\n"
 
57
                "\t<Description>" << escape(PLUGIN_DESC).c_str() << "</Description>\n"
 
58
                "\t<Website>" << escape(PLUGIN_WEB).c_str() << "</Website>\n"
 
59
                "\t<Plugin Platform=\"elf-x64\">MyPlugin-x64.so</Plugin>\n"
 
60
                "\t<Plugin Platform=\"elf-x86\">MyPlugin-x86.so</Plugin>\n"
 
61
                "\t<Plugin Platform=\"pe-x64\">MyPlugin-x64.dll</Plugin>\n"
 
62
                "\t<Plugin Platform=\"pe-x86\">MyPlugin-x86.dll</Plugin>\n"
 
63
                "\t<Files>\n"
 
64
                "\t</Files>\n"
 
65
                "</dcext>\n";
 
66
 
 
67
        return 0;
 
68
}