gcontini
2019-11-10 1c18dbea1cbd759aaf42a7e78afe0d8781065a50
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
/*
 * ApplicationFolder.cpp
 *
 *  Created on: Oct 12, 2019
 *      Author: Gabriele Contini
 */
#include <fstream>
#include <sstream>
#include <string>
 
//B#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::license_locations(
        EventRegistry &eventRegistry) {
    vector<string> diskFiles;
    char fname[MAX_PATH] = { 0 };
    const FUNCTION_RETURN fret = getModuleName(fname);
    if (fret == FUNC_RET_OK) {
        const string module_name = remove_extension(fname);
        const string temptativeLicense = string(module_name) + ".lic";
        ifstream f(temptativeLicense.c_str());
        if (f.good()) {
            diskFiles.push_back(temptativeLicense);
            eventRegistry.addEvent(LICENSE_FOUND, temptativeLicense.c_str());
        } else {
            eventRegistry.addEvent(LICENSE_FILE_NOT_FOUND, temptativeLicense.c_str());
        }
        f.close();
    } else {
        LOG_WARN("Error determining module name.");
    }
    return diskFiles;
}
 
}
} /* namespace license */