aboutsummaryrefslogtreecommitdiffstats
path: root/share/qbs/imports/qbs/BundleTools/bundle-tools.js
blob: f511bd91fca524f4b90349fb40ac9464cf75d5d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var FileInfo = loadExtension("qbs.FileInfo");
var DarwinTools = loadExtension("qbs.DarwinTools");
var PropertyList = loadExtension("qbs.PropertyList");

function destinationDirectoryForResource(product, input) {
    var path = product.destinationDirectory;
    var inputFilePath = FileInfo.joinPaths(input.baseDir, input.fileName);
    var key = DarwinTools.localizationKey(inputFilePath);
    if (key) {
        path = FileInfo.joinPaths(path, localizedResourcesFolderPath(product, key));
        var subPath = DarwinTools.relativeResourcePath(inputFilePath);
        if (subPath && subPath !== '.')
            path = FileInfo.joinPaths(path, subPath);
    } else {
        path = FileInfo.joinPaths(path, product.moduleProperty("bundle", "unlocalizedResourcesFolderPath"));
    }
    return path;
}

function localizedResourcesFolderPath(product, key) {
    return FileInfo.joinPaths(product.moduleProperty("bundle", "unlocalizedResourcesFolderPath"), key + product.moduleProperty("bundle", "localizedResourcesFolderSuffix"));
}

function infoPlistContents(infoPlistFilePath) {
    if (infoPlistFilePath === undefined)
        return undefined;

    var plist = new PropertyList();
    try {
        plist.readFromFile(infoPlistFilePath);
        return plist.toObject();
    } finally {
        plist.clear();
    }
}

function infoPlistFormat(infoPlistFilePath) {
    if (infoPlistFilePath === undefined)
        return undefined;

    var plist = new PropertyList();
    try {
        plist.readFromFile(infoPlistFilePath);
        return plist.format();
    } finally {
        plist.clear();
    }
}