// Compiled by ClojureScript 1.9.562 {:target :nodejs}
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__33063 = require("os");
return G__33063;
})().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__33068 = cljs.core.seq.call(null,subkeys);
var chunk__33069 = null;
var count__33070 = (0);
var i__33071 = (0);
while(true){
if((i__33071 < count__33070)){
var subkey = cljs.core._nth.call(null,chunk__33069,i__33071);
subkey.get("baseDir",((function (seq__33068,chunk__33069,count__33070,i__33071,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__33068,chunk__33069,count__33070,i__33071,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__33068,chunk__33069,count__33070,i__33071,subkey,n,remaining,values,Registry,win64_QMARK_,base_key,key))
,null)),null,392871351);
} 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__33068,chunk__33069,count__33070,i__33071,subkey,n,remaining,values,Registry,win64_QMARK_,base_key,key))
);

var G__33072 = seq__33068;
var G__33073 = chunk__33069;
var G__33074 = count__33070;
var G__33075 = (i__33071 + (1));
seq__33068 = G__33072;
chunk__33069 = G__33073;
count__33070 = G__33074;
i__33071 = G__33075;
continue;
} else {
var temp__5278__auto__ = cljs.core.seq.call(null,seq__33068);
if(temp__5278__auto__){
var seq__33068__$1 = temp__5278__auto__;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__33068__$1)){
var c__24249__auto__ = cljs.core.chunk_first.call(null,seq__33068__$1);
var G__33076 = cljs.core.chunk_rest.call(null,seq__33068__$1);
var G__33077 = c__24249__auto__;
var G__33078 = cljs.core.count.call(null,c__24249__auto__);
var G__33079 = (0);
seq__33068 = G__33076;
chunk__33069 = G__33077;
count__33070 = G__33078;
i__33071 = G__33079;
continue;
} else {
var subkey = cljs.core.first.call(null,seq__33068__$1);
subkey.get("baseDir",((function (seq__33068,chunk__33069,count__33070,i__33071,subkey,seq__33068__$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__33068,chunk__33069,count__33070,i__33071,subkey,seq__33068__$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__33068,chunk__33069,count__33070,i__33071,subkey,seq__33068__$1,temp__5278__auto__,n,remaining,values,Registry,win64_QMARK_,base_key,key))
,null)),null,-818609608);
} 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__33068,chunk__33069,count__33070,i__33071,subkey,seq__33068__$1,temp__5278__auto__,n,remaining,values,Registry,win64_QMARK_,base_key,key))
);

var G__33080 = cljs.core.next.call(null,seq__33068__$1);
var G__33081 = null;
var G__33082 = (0);
var G__33083 = (0);
seq__33068 = G__33080;
chunk__33069 = G__33081;
count__33070 = G__33082;
i__33071 = G__33083;
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);

}
}
}
});
