// Compiled by ClojureScript 1.9.562 {}
goog.provide('weathergen.falcon.install');
goog.require('cljs.core');
goog.require('weathergen.settings');
goog.require('taoensso.timbre');
weathergen.falcon.install.win32_QMARK_ = cljs.core._EQ_.call(null,(function (){var G__43733 = require("os");
return G__43733;
})().platform(),"win32");
weathergen.falcon.install.installations = cljs.core.atom.call(null,null);
weathergen.falcon.install.reg_read_installations = (function weathergen$falcon$install$reg_read_installations(cb){
var Registry = require("winreg");
var win64_QMARK_ = cljs.core._EQ_.call(null,"x64",process.arch);
var base_key = "\\SOFTWARE\\Benchmark Sims\\";
var key = (new Registry(({"hive": Registry.HKLM, "key": base_key, "arch": ((win64_QMARK_)?"x86":null)})));
return key.keys(((function (Registry,win64_QMARK_,base_key,key){
return (function (err,subkeys){
if(cljs.core.truth_(err)){
return cb.call(null,cljs.core.PersistentArrayMap.EMPTY);
} else {
var n = subkeys.length;
var remaining = cljs.core.atom.call(null,n);
var values = cljs.core.atom.call(null,null);
var seq__43738 = cljs.core.seq.call(null,subkeys);
var chunk__43739 = null;
var count__43740 = (0);
var i__43741 = (0);
while(true){
if((i__43741 < count__43740)){
var subkey = cljs.core._nth.call(null,chunk__43739,i__43741);
subkey.get("baseDir",((function (seq__43738,chunk__43739,count__43740,i__43741,subkey,n,remaining,values,Registry,win64_QMARK_,base_key,key){
return (function (err__$1,item){
cljs.core.swap_BANG_.call(null,remaining,cljs.core.dec);

if(cljs.core.truth_(err__$1)){
taoensso.timbre._log_BANG_.call(null,taoensso.timbre._STAR_config_STAR_,new cljs.core.Keyword(null,"error","error",-978969032),"weathergen.falcon.install",null,36,new cljs.core.Keyword(null,"p","p",151049309),new cljs.core.Keyword(null,"auto","auto",-566279492),(new cljs.core.Delay(((function (seq__43738,chunk__43739,count__43740,i__43741,subkey,n,remaining,values,Registry,win64_QMARK_,base_key,key){
return (function (){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, ["Could not read from registry key ",subkey.path], null);
});})(seq__43738,chunk__43739,count__43740,i__43741,subkey,n,remaining,values,Registry,win64_QMARK_,base_key,key))
,null)),null,-13815549);
} else {
cljs.core.swap_BANG_.call(null,values,cljs.core.assoc,cljs.core.subs.call(null,subkey.key,cljs.core.count.call(null,base_key)),item.value);
}

if((cljs.core.deref.call(null,remaining) === (0))){
return cb.call(null,cljs.core.deref.call(null,values));
} else {
return null;
}
});})(seq__43738,chunk__43739,count__43740,i__43741,subkey,n,remaining,values,Registry,win64_QMARK_,base_key,key))
);

var G__43742 = seq__43738;
var G__43743 = chunk__43739;
var G__43744 = count__43740;
var G__43745 = (i__43741 + (1));
seq__43738 = G__43742;
chunk__43739 = G__43743;
count__43740 = G__43744;
i__43741 = G__43745;
continue;
} else {
var temp__5278__auto__ = cljs.core.seq.call(null,seq__43738);
if(temp__5278__auto__){
var seq__43738__$1 = temp__5278__auto__;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__43738__$1)){
var c__24249__auto__ = cljs.core.chunk_first.call(null,seq__43738__$1);
var G__43746 = cljs.core.chunk_rest.call(null,seq__43738__$1);
var G__43747 = c__24249__auto__;
var G__43748 = cljs.core.count.call(null,c__24249__auto__);
var G__43749 = (0);
seq__43738 = G__43746;
chunk__43739 = G__43747;
count__43740 = G__43748;
i__43741 = G__43749;
continue;
} else {
var subkey = cljs.core.first.call(null,seq__43738__$1);
subkey.get("baseDir",((function (seq__43738,chunk__43739,count__43740,i__43741,subkey,seq__43738__$1,temp__5278__auto__,n,remaining,values,Registry,win64_QMARK_,base_key,key){
return (function (err__$1,item){
cljs.core.swap_BANG_.call(null,remaining,cljs.core.dec);

if(cljs.core.truth_(err__$1)){
taoensso.timbre._log_BANG_.call(null,taoensso.timbre._STAR_config_STAR_,new cljs.core.Keyword(null,"error","error",-978969032),"weathergen.falcon.install",null,36,new cljs.core.Keyword(null,"p","p",151049309),new cljs.core.Keyword(null,"auto","auto",-566279492),(new cljs.core.Delay(((function (seq__43738,chunk__43739,count__43740,i__43741,subkey,seq__43738__$1,temp__5278__auto__,n,remaining,values,Registry,win64_QMARK_,base_key,key){
return (function (){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, ["Could not read from registry key ",subkey.path], null);
});})(seq__43738,chunk__43739,count__43740,i__43741,subkey,seq__43738__$1,temp__5278__auto__,n,remaining,values,Registry,win64_QMARK_,base_key,key))
,null)),null,1803059709);
} else {
cljs.core.swap_BANG_.call(null,values,cljs.core.assoc,cljs.core.subs.call(null,subkey.key,cljs.core.count.call(null,base_key)),item.value);
}

if((cljs.core.deref.call(null,remaining) === (0))){
return cb.call(null,cljs.core.deref.call(null,values));
} else {
return null;
}
});})(seq__43738,chunk__43739,count__43740,i__43741,subkey,seq__43738__$1,temp__5278__auto__,n,remaining,values,Registry,win64_QMARK_,base_key,key))
);

var G__43750 = cljs.core.next.call(null,seq__43738__$1);
var G__43751 = null;
var G__43752 = (0);
var G__43753 = (0);
seq__43738 = G__43750;
chunk__43739 = G__43751;
count__43740 = G__43752;
i__43741 = G__43753;
continue;
}
} else {
return null;
}
}
break;
}
}
});})(Registry,win64_QMARK_,base_key,key))
);
});
/**
 * Invokes cb with a map from installation names to their installation directories.
 */
weathergen.falcon.install.locate_installations = (function weathergen$falcon$install$locate_installations(cb){
var cached = cljs.core.deref.call(null,weathergen.falcon.install.installations);
var override = new cljs.core.Keyword(null,"installations","installations",-2091217739).cljs$core$IFn$_invoke$arity$1(weathergen.settings.load_settings.call(null));
if(cljs.core.truth_(cached)){
return cb.call(null,cached);
} else {
if(cljs.core.truth_(override)){
cljs.core.reset_BANG_.call(null,weathergen.falcon.install.installations,override);

return cb.call(null,override);
} else {
if(weathergen.falcon.install.win32_QMARK_){
return weathergen.falcon.install.reg_read_installations.call(null,((function (cached,override){
return (function (val){
cljs.core.reset_BANG_.call(null,weathergen.falcon.install.installations,val);

return cb.call(null,val);
});})(cached,override))
);
} else {
return cb.call(null,null);

}
}
}
});
