|
#include <iostream> |
|
#include <fstream> |
|
#include <sstream> |
|
#include <string> |
|
#include <jsoncpp/json/json.h> |
|
|
|
int main(int argc, const char * argv[]) { |
|
if (argc < 4) { |
|
std::cout << "Usage: " << argv[0] << " <program name> <program path> <app name> [icon path]"; |
|
return 1; |
|
} |
|
std::string icon; |
|
if (argc > 4) { |
|
icon = std::string(argv[4]); |
|
} else { |
|
icon = "icon_128.png"; |
|
} |
|
Json::Value root; |
|
std::ifstream in; |
|
std::ofstream out; |
|
in.open("programs.json"); |
|
//std::stringstream pro; |
|
//std::string p; |
|
//in >> p; |
|
//std::cout << ":" << p << "\n"; |
|
//pro << p; |
|
//pro >> root; |
|
in >> root; |
|
in.close(); |
|
std::string id = root["id"].asString(); |
|
if (!root.isMember(argv[1])) root["keys"].append(Json::Value(argv[1])); |
|
root[argv[1]] = Json::Value(argv[2]); |
|
out.open("programs.json"); |
|
out << root; |
|
out.close(); |
|
std::string dir("" + std::string(argv[1]) + "/"); |
|
system(std::string("mkdir " + dir).c_str()); |
|
Json::Value manifest; |
|
manifest["name"] = Json::Value(argv[3]); |
|
manifest["description"] = Json::Value("Crouton app wrapper"); |
|
manifest["version"] = Json::Value("1.0"); |
|
manifest["manifest_version"] = Json::Value(2); |
|
manifest["icons"] = Json::Value(Json::objectValue); |
|
manifest["icons"]["128"] = Json::Value("icon_128.png"); |
|
manifest["app"] = Json::Value(Json::objectValue); |
|
manifest["app"]["background"] = Json::Value(Json::objectValue); |
|
manifest["app"]["background"]["scripts"] = Json::Value(Json::arrayValue); |
|
manifest["app"]["background"]["scripts"].append(Json::Value("background.js")); |
|
out.open(std::string(dir + "manifest.json").c_str()); |
|
out << manifest; |
|
out.close(); |
|
out.open(std::string(dir + "background.js").c_str()); |
|
out << "var xhr = new XMLHttpRequest(); xhr.open(\"GET\", \"http://dweet.io/dweet/for/croutonapp" << id << "?program=" << argv[1] << "\", true); xhr.setRequestHeader(\"Content-Type\", \"text/json; charset=UTF-8\"); xhr.send();"; |
|
out.close(); |
|
system(std::string("cp " + icon + " " + dir + "icon_128.png").c_str()); |
|
system(std::string("crxmake --pack-extension=" + dir).c_str()); |
|
std::cout << "programs.json has been updated, and the extension has been created as " << dir << "\b.crx.\n"; |
|
return 0; |
|
} |