// 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__32873 = require("os");
return G__32873;
})().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__32878 = cljs.core.seq.call(null,subkeys);
var chunk__32879 = null;
var count__32880 = (0);
var i__32881 = (0);
while(true){
if((i__32881 < count__32880)){
var subkey = cljs.core._nth.call(null,chunk__32879,i__32881);
subkey.get("baseDir",((function (seq__32878,chunk__32879,count__32880,i__32881,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__32878,chunk__32879,count__32880,i__32881,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__32878,chunk__32879,count__32880,i__32881,subkey,n,remaining,values,Registry,win64_QMARK_,base_key,key))
,null)),null,116618097);
} 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__32878,chunk__32879,count__32880,i__32881,subkey,n,remaining,values,Registry,win64_QMARK_,base_key,key))
);

var G__32882 = seq__32878;
var G__32883 = chunk__32879;
var G__32884 = count__32880;
var G__32885 = (i__32881 + (1));
seq__32878 = G__32882;
chunk__32879 = G__32883;
count__32880 = G__32884;
i__32881 = G__32885;
continue;
} else {
var temp__5278__auto__ = cljs.core.seq.call(null,seq__32878);
if(temp__5278__auto__){
var seq__32878__$1 = temp__5278__auto__;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__32878__$1)){
var c__24059__auto__ = cljs.core.chunk_first.call(null,seq__32878__$1);
var G__32886 = cljs.core.chunk_rest.call(null,seq__32878__$1);
var G__32887 = c__24059__auto__;
var G__32888 = cljs.core.count.call(null,c__24059__auto__);
var G__32889 = (0);
seq__32878 = G__32886;
chunk__32879 = G__32887;
count__32880 = G__32888;
i__32881 = G__32889;
continue;
} else {
var subkey = cljs.core.first.call(null,seq__32878__$1);
subkey.get("baseDir",((function (seq__32878,chunk__32879,count__32880,i__32881,subkey,seq__32878__$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__32878,chunk__32879,count__32880,i__32881,subkey,seq__32878__$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__32878,chunk__32879,count__32880,i__32881,subkey,seq__32878__$1,temp__5278__auto__,n,remaining,values,Registry,win64_QMARK_,base_key,key))
,null)),null,1897220273);
} 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__32878,chunk__32879,count__32880,i__32881,subkey,seq__32878__$1,temp__5278__auto__,n,remaining,values,Registry,win64_QMARK_,base_key,key))
);

var G__32890 = cljs.core.next.call(null,seq__32878__$1);
var G__32891 = null;
var G__32892 = (0);
var G__32893 = (0);
seq__32878 = G__32890;
chunk__32879 = G__32891;
count__32880 = G__32892;
i__32881 = G__32893;
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);

}
}
}
});
