const{app:app}=require("electron"),path=require("path"),fs=require("fs"),JsonStorage=require("./JsonStorage"),{version:version}=require("os"),{get:get}=require("http"),__CONFIG_PATH=path.join(__dirname,"config.json"),UPDATES_PATH=path.join(app.getPath("userData"),"bgxiong_updates");fs.existsSync(UPDATES_PATH)||fs.mkdirSync(UPDATES_PATH,{recursive:!0});const CONFIG_PATH=path.join(UPDATES_PATH,"bgxiong-config.json");function isConfigValid(config){return!(!config||"object"!=typeof config||0===Object.keys(config).length)&&!(!config.version||"string"!=typeof config.version||0===config.version.trim().length)}function configRebuilder(){let defaultConfig;try{const defaultData=fs.readFileSync(__CONFIG_PATH,"utf8");defaultConfig=JSON.parse(defaultData)}catch(err){throw new Error(`Failed to load default config from ${__CONFIG_PATH}: ${err.message}`)}try{fs.writeFileSync(CONFIG_PATH,JSON.stringify(defaultConfig,null,2),"utf8")}catch(err){}return defaultConfig}function loadConfig(){let defaultConfig;if(fs.existsSync(CONFIG_PATH))try{const data=fs.readFileSync(CONFIG_PATH,"utf8");return data&&""!==data.trim()?(defaultConfig=JSON.parse(data),isConfigValid(defaultConfig)?defaultConfig:configRebuilder()):configRebuilder()}catch(err){try{fs.unlinkSync(CONFIG_PATH)}catch(e){}return configRebuilder()}return configRebuilder()}function isConfigValid(config){return!(!config||"object"!=typeof config||0===Object.keys(config).length)&&!(!config.version||"string"!=typeof config.version||0===config.version.trim().length)}let pluginConfig=loadConfig();const config=new JsonStorage(CONFIG_PATH);function getCurrentPage(){return config.get("user.current_page","sounds")}function setCurrentPage(value){return config.set("user.current_page",value)}function getUserToken(){return config.get("user.token","")}function setUserToken(token){return config.set("user.token",token)}function getLastProjectPath(){return config.get("project.lastPath","")}function setLastProjectPath(path){return config.set("project.lastPath",path)}function setUserInfo(userInfo){return config.set("user.info",userInfo)}function getUserInfo(){return config.get("user.info")}function getVersion(){return config.get("version")}function setVersion(version){return config.set("version",version)}function getAll(){return config.getAll()}function reload(){return config.reload()}function getUserDataPath(){return app.getPath("userData")}function getUpdatePath(){return UPDATES_PATH}function getBGXiongDataPath(){return path.join(getUserDataPath(),"bgxiong_data")}function getApiBaseUrl(){return(config.getAll().api_base_url||"https://www.bgxiong.com").trim()}module.exports={getCurrentPage:getCurrentPage,setCurrentPage:setCurrentPage,getUserToken:getUserToken,setUserInfo:setUserInfo,getUserInfo:getUserInfo,setUserToken:setUserToken,getLastProjectPath:getLastProjectPath,setLastProjectPath:setLastProjectPath,getVersion:getVersion,setVersion:setVersion,getAll:getAll,reload:reload,getUserDataPath:getUserDataPath,getBGXiongDataPath:getBGXiongDataPath,getUpdatePath:getUpdatePath,getApiBaseUrl:getApiBaseUrl};