// Compiled by ClojureScript 1.10.520 {}
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__40301 = require("os");
return G__40301;
})().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__40302 = cljs.core.seq.call(null,subkeys);
var chunk__40303 = null;
var count__40304 = (0);
var i__40305 = (0);
while(true){
if((i__40305 < count__40304)){
var subkey = cljs.core._nth.call(null,chunk__40303,i__40305);
subkey.get("baseDir",((function (seq__40302,chunk__40303,count__40304,i__40305,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__40302,chunk__40303,count__40304,i__40305,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__40302,chunk__40303,count__40304,i__40305,subkey,n,remaining,values,Registry,win64_QMARK_,base_key,key))
,null)),null,-856482821);
} 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__40302,chunk__40303,count__40304,i__40305,subkey,n,remaining,values,Registry,win64_QMARK_,base_key,key))
);


var G__40306 = seq__40302;
var G__40307 = chunk__40303;
var G__40308 = count__40304;
var G__40309 = (i__40305 + (1));
seq__40302 = G__40306;
chunk__40303 = G__40307;
count__40304 = G__40308;
i__40305 = G__40309;
continue;
} else {
var temp__5720__auto__ = cljs.core.seq.call(null,seq__40302);
if(temp__5720__auto__){
var seq__40302__$1 = temp__5720__auto__;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__40302__$1)){
var c__4550__auto__ = cljs.core.chunk_first.call(null,seq__40302__$1);
var G__40310 = cljs.core.chunk_rest.call(null,seq__40302__$1);
var G__40311 = c__4550__auto__;
var G__40312 = cljs.core.count.call(null,c__4550__auto__);
var G__40313 = (0);
seq__40302 = G__40310;
chunk__40303 = G__40311;
count__40304 = G__40312;
i__40305 = G__40313;
continue;
} else {
var subkey = cljs.core.first.call(null,seq__40302__$1);
subkey.get("baseDir",((function (seq__40302,chunk__40303,count__40304,i__40305,subkey,seq__40302__$1,temp__5720__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__40302,chunk__40303,count__40304,i__40305,subkey,seq__40302__$1,temp__5720__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__40302,chunk__40303,count__40304,i__40305,subkey,seq__40302__$1,temp__5720__auto__,n,remaining,values,Registry,win64_QMARK_,base_key,key))
,null)),null,-257969044);
} 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__40302,chunk__40303,count__40304,i__40305,subkey,seq__40302__$1,temp__5720__auto__,n,remaining,values,Registry,win64_QMARK_,base_key,key))
);


var G__40314 = cljs.core.next.call(null,seq__40302__$1);
var G__40315 = null;
var G__40316 = (0);
var G__40317 = (0);
seq__40302 = G__40314;
chunk__40303 = G__40315;
count__40304 = G__40316;
i__40305 = G__40317;
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);

}
}
}
});
