Skip to content

Commit a36338f

Browse files
author
BunnyBlue
committed
update shared resource
1 parent 4c0e8cd commit a36338f

5 files changed

Lines changed: 667 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//
2+
// AaptConfig.cpp
3+
// AaptExt
4+
//
5+
// Created by BunnyBlue on 6/25/15.
6+
// Copyright © 2015 BunnyBlue. All rights reserved.
7+
//
8+
9+
#include "AaptConfig.h"
10+
AaptConfig::Object_Creator AaptConfig::_object_creator;
11+
12+
std::string inline delSpaces(std::string &str)
13+
{
14+
str.erase(std::remove(str.begin(), str.end(), ' '), str.end());
15+
return str;
16+
}
17+
18+
bool acceptKey(std::string key){
19+
20+
if(key.compare(AAPT_CONFIG_PKG)==0){
21+
return true;
22+
}
23+
if (key.compare(AAPT_CONFIG_PREBUILD_PKG_PATH)==0) {
24+
return true;
25+
}
26+
if (key.compare(AAPT_CONFIG_PKG_GROUP_ID)==0) {
27+
return true;
28+
}
29+
if (key.compare(AAPT_CONFIG_PKG_VERSION_NAME)==0) {
30+
return true;
31+
}
32+
33+
return false;
34+
35+
}
36+
void AaptConfig::read_file(std::istream& is)
37+
{
38+
39+
options.clear();
40+
for(;;) {
41+
std::string line;
42+
std::getline(is, line);
43+
if(!is) break;
44+
std::istringstream is_line(line);
45+
std::string key;
46+
if( std::getline(is_line, key, '=') )
47+
{
48+
std::string value;
49+
if( std::getline(is_line, value) ){
50+
key=delSpaces(key);
51+
value=delSpaces(value);
52+
if (acceptKey(key)) {
53+
options.insert(std::pair<std::string, std::string>(key,value));
54+
}else{
55+
std::cout<<"unknown key!!! "<<key<<"\n";
56+
}
57+
58+
59+
}
60+
}
61+
62+
}
63+
if(!is.eof()) {
64+
return;
65+
}
66+
}
67+
std::string AaptConfig::getConfigByKey(const std::string key){
68+
map<string,string>::iterator itr=options.find(key);
69+
if (itr==options.end()) {
70+
return nullptr;
71+
}
72+
return itr->second;
73+
74+
}
75+
void AaptConfig::initConfigFile(std::string path){
76+
std::ifstream ifs( path.c_str());
77+
if(!ifs.good()) {
78+
79+
return;
80+
}
81+
read_file(ifs);
82+
83+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// AaptConfig.h
3+
// AaptExt
4+
//
5+
// Created by BunnyBlue on 6/25/15.
6+
// Copyright © 2015 BunnyBlue. All rights reserved.
7+
//
8+
9+
#ifndef AaptConfig_h
10+
#define AaptConfig_h
11+
12+
#include <stdio.h>
13+
#include <iostream>
14+
#include <string>
15+
#include <sstream>
16+
#include <fstream>
17+
#include <map>
18+
#define AAPT_CONFIG_PKG "pkg"//define prebuild source package name
19+
#define AAPT_CONFIG_PREBUILD_PKG_PATH "preBuildJarPath"//prebuild Shared Package Resouces
20+
#define AAPT_CONFIG_PKG_GROUP_ID "pkgGroupId"// plugin package group id
21+
#define AAPT_CONFIG_PKG_VERSION_NAME "versionName"//plugin package versionName
22+
using namespace std;
23+
class AaptConfig
24+
{
25+
public:
26+
static AaptConfig* getInstance()
27+
{
28+
static AaptConfig instance;
29+
return &instance;
30+
}
31+
void initConfigFile(std::string path);
32+
std::string getConfigByKey(const std::string key);
33+
34+
protected:
35+
struct Object_Creator
36+
{
37+
Object_Creator()
38+
{
39+
AaptConfig::getInstance();
40+
}
41+
};
42+
static Object_Creator _object_creator;
43+
std::string _conFilePath;
44+
45+
std::map<std::string, std::string> options;
46+
void read_file(std::istream& is);
47+
AaptConfig() {
48+
49+
}
50+
~AaptConfig() {}
51+
};
52+
53+
#endif /* AaptConfig_cpp */
54+
/*
55+
config should be
56+
pkg=io.github.bunnyblue.pkg
57+
preBuildJarPath=/Users/Downloads/prebuild.jar
58+
pkgGroupId=0x1a
59+
unusedkey=unusedvalue
60+
*/

0 commit comments

Comments
 (0)