gcontini
2019-10-12 dda16735b94661b798d6c0fd3e41af944de0a1fe
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
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * ApplicationFolder.cpp
 *
 *  Created on: Oct 12, 2019
 *      Author: Gabriele Contini
 */
#include <fstream>
#include <sstream>
#include <string>
 
#include <build_properties.h>
 
#include "../base/logger.h"
#include "../api/datatypes.h"
#include "../base/base.h"
#include "../base/EventRegistry.h"
#include "../base/FileUtils.hpp"
#include "../os/os.h"
#include "ApplicationFolder.hpp"
#include <iostream>
 
namespace license {
namespace locate {
using namespace std;
 
ApplicationFolder::ApplicationFolder() :
        LocatorStrategy("ApplicationFolder") {
 
}
 
ApplicationFolder::~ApplicationFolder() {
}
 
const vector<string> ApplicationFolder::licenseLocations(
        EventRegistry &eventRegistry) const {
    vector<string> diskFiles;
    char fname[MAX_PATH] = { 0 };
    const FUNCTION_RETURN fret = getModuleName(fname);
    cout << string(fname) << endl;
    cout << fret << endl;
    if (fret == FUNC_RET_OK) {
        const string temptativeLicense = string(fname) + ".lic";
        ifstream f(temptativeLicense.c_str());
        if (f.good()) {
            diskFiles.push_back(temptativeLicense);
            eventRegistry.addEvent((EVENT_TYPE) LICENSE_FILE_FOUND,
                    (SEVERITY) SVRT_INFO, temptativeLicense);
        } else {
            eventRegistry.addEvent(LICENSE_FILE_NOT_FOUND, SVRT_WARN,
                    temptativeLicense);
        }
        f.close();
    } else {
        LOG_WARN("Error determining module name.");
    }
    return diskFiles;
}
 
}
} /* namespace license */