GameEnvManager_launcher.lua 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950
  1. local GameEnvManager = class("GameEnvManager")
  2. local AssetsManager = requireLauncher( "res_check/assets_manager" )
  3. local cjson = require("cjson")
  4. local defaultChannelID = "1"
  5. local Tags = "LauncherUpdater"
  6. local AppOverlayTraceFile = "overlay_trace"
  7. cc.PRIORITY_NON_SYSTEM_MIN = -2147483647
  8. GameEnvManager.startPath = "res/private/start_game/"
  9. function GameEnvManager:ctor()
  10. self._resVersion = "?v=1.1.1"
  11. self._rootDomain = ""
  12. self._gmName = "" -- gm 唯一标记
  13. self._signkey = "" -- 登录、支付加密密钥
  14. self._gmSearchPath = "" -- gm 资源搜索路径
  15. self._gmCachePath = "" -- gm cache路径
  16. self._channelID = nil -- 渠道商id,类型:字符串, ANDROID:读取cID.txt文件 IOS:底层传入 WINDOWS:默认"1"
  17. self._modeInfoURL = "http://list-new.dhsf.xqhuyu.com/modlist/modlist_%s.txt"
  18. self._modeInfoURLPlanB = "" -- 备选域名
  19. self._launcherSuffix = nil -- launcher 远端资源后缀
  20. self._modlistCustomData = {}
  21. self._downloader = nil
  22. -- apk info
  23. self._isReview = false -- 是否审核服
  24. self.apkVersionName = "1.1.1"
  25. self.apkVersionCode = "111"
  26. self.apkPackageName = "package"
  27. self.apkPackageShowName = ""
  28. self._battery = 100
  29. self._netType = 0
  30. self._deviceRotation = 1 -- 刘海屏所在方向 1.刘海屏在左 3.刘海屏在右
  31. self._totalMemSizeInGB = 3
  32. self._UDID = "xxx"
  33. self._PUID = "xxx"
  34. self._sData = nil
  35. self._macAddress = nil
  36. self._isEMU = false
  37. self._isUM = false
  38. self._needPermission = false -- 需要权限才能进游戏
  39. self._hasPermission = false -- 是否拥有权限
  40. -- launcher data
  41. self._launcherSrvID = nil -- 登录器 传入的服务器ID
  42. self._launcherWhitelist = nil -- 登录器 传入白名单
  43. self._envData = {}
  44. self._launchERROR = false -- 启动失败
  45. -- gm data
  46. self._gmLoadingData = {}
  47. -- 下载失败计数
  48. self._downloadEasyCount = {}
  49. self._isGameSuspend = false -- 游戏正在暂停
  50. self._suspendCBCache = {} -- 暂停时的回调缓存
  51. -- modlist request sign
  52. self._modlistSignKey = "shPUZw4ncV5oJ3Hu"
  53. self._modlistURLList = {}
  54. self._modlistURLIndex = 0
  55. self._modlistURLCount = 0
  56. --强更
  57. self._apkUpdateInfoUrl = nil
  58. self._javaVersionCode = nil
  59. self._hasInstallPermission = false --是否有应用内安装权限
  60. self._apkUpdateInfo = {}
  61. end
  62. ---------------------------------- domain ------------------------------------
  63. function GameEnvManager:SetResVersion( ver )
  64. self._resVersion = ver
  65. end
  66. function GameEnvManager:GetResVersion()
  67. return self._resVersion
  68. end
  69. function GameEnvManager:SetRootDomain( domain )
  70. self._rootDomain = domain
  71. end
  72. function GameEnvManager:GetRootDomain()
  73. return self._rootDomain
  74. end
  75. function GameEnvManager:SetRootDomain2( domain )
  76. self._rootDomain2 = domain
  77. end
  78. function GameEnvManager:GetRootDomain2()
  79. return self._rootDomain2
  80. end
  81. ---------------------------------- domain ------------------------------------
  82. -- review server
  83. function GameEnvManager:SetIsReview( status )
  84. self._isReview = status
  85. end
  86. function GameEnvManager:IsReview()
  87. return self._isReview
  88. end
  89. function GameEnvManager:checkReview()
  90. local restart = false
  91. -- check alpha status
  92. if self:IsReview() then
  93. releasePrint("alpha flag:in review")
  94. if not g_isAlpha then -- delete alpha file
  95. if global.L_ModuleManager:IsCurrentModuleAlphaStateExist() then
  96. releasePrint("alpha flag: delete !alpha flag and restart")
  97. global.L_ModuleManager:CleanCurrentModuleAlphaState()
  98. restart = true
  99. self:RestartGame()
  100. end
  101. end
  102. else
  103. releasePrint("alpha flag:not in review")
  104. if g_isAlpha then -- record alpha file
  105. if not global.L_ModuleManager:IsCurrentModuleAlphaStateExist() then
  106. releasePrint("alpha flag: record !alpha flag and restart")
  107. global.L_ModuleManager:StoreCurrentModuleAlphaState()
  108. restart = true
  109. self:RestartGame()
  110. end
  111. end
  112. end
  113. return restart
  114. end
  115. -- review server
  116. -- apk info
  117. function GameEnvManager:SetAPKVersionName( name )
  118. self.apkVersionName = name
  119. end
  120. function GameEnvManager:GetAPKVersionName()
  121. return self.apkVersionName
  122. end
  123. function GameEnvManager:SetAPKVersionCode(code)
  124. self.apkVersionCode = code
  125. end
  126. function GameEnvManager:GetAPKVersionCode()
  127. return self.apkVersionCode
  128. end
  129. function GameEnvManager:SetAPKPackageName( name )
  130. self.apkPackageName = name
  131. end
  132. function GameEnvManager:GetAPKPackageName()
  133. return self.apkPackageName
  134. end
  135. function GameEnvManager:SetAPKPackageShowName( name )
  136. self.apkPackageShowName = name
  137. end
  138. function GameEnvManager:GetAPKPackageShowName()
  139. return self.apkPackageShowName
  140. end
  141. function GameEnvManager:SetAPKUpdateInfoUrl( url )
  142. self._apkUpdateInfoUrl = url
  143. end
  144. function GameEnvManager:GetAPKUpdateInfoUrl()
  145. return self._apkUpdateInfoUrl
  146. end
  147. function GameEnvManager:SetJavaVersionCode(code)
  148. self._javaVersionCode = code
  149. end
  150. function GameEnvManager:GetJavaVersionCode()
  151. return self._javaVersionCode
  152. end
  153. function GameEnvManager:SetHasInstallPermission(hasInstallPermission)
  154. self._hasInstallPermission = hasInstallPermission
  155. end
  156. function GameEnvManager:GetHasInstallPermission()
  157. return self._hasInstallPermission
  158. end
  159. -- "update_content" = "线上分包测试安卓"
  160. -- "update_url" = "url..."
  161. -- "update_ver_code" = 400000054
  162. -- "update_ver_name" = "4.5.4"
  163. function GameEnvManager:SetAPKUpdateInfo(info)
  164. self._apkUpdateInfo = info
  165. end
  166. function GameEnvManager:GetAPKUpdateInfo()
  167. return self._apkUpdateInfo
  168. end
  169. -- apk info
  170. -- native status
  171. function GameEnvManager:SetBattery(battery)
  172. self._battery = battery
  173. end
  174. function GameEnvManager:GetBattery()
  175. return self._battery
  176. end
  177. function GameEnvManager:SetNetType(type)
  178. -- -1:未识别 0:wifi 1:2g 2:3g 3:4g
  179. self._netType = type
  180. end
  181. function GameEnvManager:GetNetType()
  182. return self._netType
  183. end
  184. function GameEnvManager:SetDeviceRotation(rotation)
  185. self._deviceRotation = rotation
  186. end
  187. function GameEnvManager:GetDeviceRotation()
  188. return self._deviceRotation
  189. end
  190. function GameEnvManager:SetTotalMemSize(memsize)
  191. self._totalMemSizeInGB = memsize
  192. end
  193. function GameEnvManager:GetTotalMemSize()
  194. return self._totalMemSizeInGB
  195. end
  196. function GameEnvManager:SetUDID(udid)
  197. self._UDID = udid
  198. end
  199. function GameEnvManager:GetUDID()
  200. return self._UDID
  201. end
  202. function GameEnvManager:SetPUID(puid)
  203. self._PUID = puid
  204. end
  205. function GameEnvManager:GetPUID()
  206. return self._PUID
  207. end
  208. function GameEnvManager:SetSData( sData )
  209. self._sData = sData
  210. end
  211. function GameEnvManager:GetSData()
  212. return self._sData
  213. end
  214. function GameEnvManager:SetMacAddress( mac )
  215. self._macAddress = mac
  216. end
  217. function GameEnvManager:GetMacAddress()
  218. return self._macAddress
  219. end
  220. function GameEnvManager:SetIsEmulator(value)
  221. self._isEMU = value
  222. end
  223. function GameEnvManager:IsEmulator()
  224. return self._isEMU
  225. end
  226. function GameEnvManager:SetIsUmeng(value)
  227. self._isUM = value
  228. end
  229. function GameEnvManager:IsUmeng()
  230. return self._isUM
  231. end
  232. function GameEnvManager:setNeedPermission(value)
  233. self._needPermission = value
  234. end
  235. function GameEnvManager:isNeedPermission()
  236. return self._needPermission
  237. end
  238. function GameEnvManager:setHasPermission(value)
  239. self._hasPermission = value
  240. end
  241. function GameEnvManager:isHasPermission()
  242. return self._hasPermission
  243. end
  244. -- native status
  245. ---------------------------------- gm data ------------------------------------
  246. function GameEnvManager:SetGMLoadingData(v)
  247. self._gmLoadingData = v
  248. end
  249. function GameEnvManager:GetGMLoadingData()
  250. return self._gmLoadingData
  251. end
  252. ---------------------------------- mod info ------------------------------------
  253. function GameEnvManager:ReportError(str, callback)
  254. local tipsData = {
  255. btnType = 1,
  256. str = str,
  257. callback = callback
  258. }
  259. global.L_CommonTipsManager:OpenLayer( tipsData )
  260. end
  261. function GameEnvManager:SetChannelID( channel )
  262. self._channelID = channel
  263. end
  264. function GameEnvManager:GetChannelID()
  265. return self._channelID
  266. end
  267. function GameEnvManager:SetGMName(gmname)
  268. self._gmName = gmname
  269. end
  270. function GameEnvManager:GetGMName()
  271. return self._gmName
  272. end
  273. function GameEnvManager:SetSignkey(signkey)
  274. self._signkey = signkey
  275. end
  276. function GameEnvManager:GetSignkey()
  277. return self._signkey
  278. end
  279. function GameEnvManager:SetModInfoURL( url )
  280. self._modeInfoURL = url
  281. end
  282. function GameEnvManager:GetModInfoURL()
  283. return self._modeInfoURL
  284. end
  285. function GameEnvManager:SetModInfoURLPlanB( url )
  286. self._modeInfoURLPlanB = url
  287. end
  288. function GameEnvManager:GetModInfoURLPlanB()
  289. return self._modeInfoURLPlanB
  290. end
  291. function GameEnvManager:SetLauncherUrlSuffix( suffix )
  292. self._launcherSuffix = suffix
  293. end
  294. function GameEnvManager:GetLauncherUrlSuffix()
  295. return self._launcherSuffix
  296. end
  297. function GameEnvManager:SetGMSearchPath( path )
  298. self._gmSearchPath = path
  299. end
  300. function GameEnvManager:GetGMSearchPath()
  301. return self._gmSearchPath
  302. end
  303. function GameEnvManager:SetGMCachePath( path )
  304. self._gmCachePath = path
  305. end
  306. function GameEnvManager:GetGMCachePath()
  307. return self._gmCachePath
  308. end
  309. function GameEnvManager:SetModlistCustomData( data )
  310. self._modlistCustomData = data
  311. end
  312. function GameEnvManager:GetModlistCustomData()
  313. return self._modlistCustomData
  314. end
  315. function GameEnvManager:GetModlistCustomDataByKey(key)
  316. if not self._modlistCustomData then
  317. return nil
  318. end
  319. return self._modlistCustomData[key]
  320. end
  321. function GameEnvManager:GetModlistSignKey()
  322. return self._modlistSignKey
  323. end
  324. function GameEnvManager:LoadGameInfo()
  325. -- 启动文件异常
  326. if global.isWindows and not global.isDebugMode and not global.isGMMode and self._launchERROR then
  327. self:ReportError("启动文件异常")
  328. return false
  329. end
  330. -- 停止定时器
  331. if self._scheduleID then
  332. UnSchedule( self._scheduleID )
  333. self._scheduleID = nil
  334. end
  335. -- 向底层请求渠道号
  336. local count = 0
  337. local limit = 25
  338. local function callback()
  339. count = count + 1
  340. if global.isMobile then
  341. local jData = {}
  342. jData.needUDID = 1
  343. global.L_NativeBridgeManager:GN_appLaunchNotify(jData)
  344. end
  345. -- 有渠道号
  346. if self:GetChannelID() and string.len(self:GetChannelID()) > 0 then
  347. if self._scheduleID then
  348. UnSchedule( self._scheduleID )
  349. self._scheduleID = nil
  350. end
  351. -- request modinfo list
  352. self:RequestModlistURL()
  353. return nil
  354. end
  355. if count >= limit and (nil == self:GetChannelID() or 0 == string.len(self:GetChannelID())) then
  356. -- 获取失败
  357. if self._scheduleID then
  358. UnSchedule( self._scheduleID )
  359. self._scheduleID = nil
  360. end
  361. -- 联系客服
  362. self:ReportError("启动环境参数异常,请退出重试!", function()
  363. self:LoadGameInfo()
  364. end)
  365. end
  366. end
  367. self._scheduleID = Schedule(callback, 0.2)
  368. callback()
  369. end
  370. function GameEnvManager:decodeModlistXXTEA(response)
  371. local fileUtil = cc.FileUtils:getInstance()
  372. local filePath = fileUtil:getWritablePath() .. "temp_decode"
  373. if fileUtil:isFileExist(filePath) then
  374. fileUtil:removeFile(filePath)
  375. end
  376. fileUtil:writeStringToFile(response, filePath)
  377. response = fileUtil:getDataFromFileEx(filePath)
  378. return response
  379. end
  380. function GameEnvManager:decodeModlist(response)
  381. return cjson.decode( decodeServerInfo(response) )
  382. end
  383. function GameEnvManager:AddModlistCacheNamePrefix(cacheName)
  384. return string.format("%s_%s", cacheName, self:GetChannelID())
  385. end
  386. function GameEnvManager:RequestModlistURL()
  387. -- 重新请求
  388. local function retry()
  389. self:RequestModlistURL()
  390. end
  391. -- http数据请求回调
  392. local function callback(success, response, url, code)
  393. HideLoadingBar()
  394. self._modlistURLCount = self._modlistURLCount + 1
  395. -- 拉取失败
  396. if not success then
  397. if self._modlistURLIndex == 0 then --主域名
  398. global.L_DataRePort:ReportErrorModlistURL("MODLIST_URL_REQUEST_FAILED_MAIN", "-1000", "Request main modlist URL ERROR, CODE ERROR", url, -2)
  399. else
  400. global.L_DataRePort:ReportErrorModlistURL("MODLIST_URL_REQUEST_FAILED_PLANB", "-1000", "Request planb modlist URL ERROR, CODE ERROR", url, -2)
  401. end
  402. if self._modlistURLIndex == 0 and self._modlistURLCount >= 3 then
  403. self:ReportError("[modlist][URL][0]网络不给力哦!点“确认”重试。", retry)
  404. -- 上报至服务器
  405. global.L_DataRePort:ReportErrorModlistURL("MODLIST_URL_REQUEST_FAILED", "-1000", "Request modlist URL ERROR, CODE ERROR", url, code)
  406. else
  407. retry()
  408. end
  409. return nil
  410. end
  411. -- 数据异常
  412. if not response then
  413. if self._modlistURLIndex == 0 then --主域名
  414. global.L_DataRePort:ReportErrorModlistURL("MODLIST_URL_REQUEST_FAILED_MAIN", "-1001", "Request main modlist URL ERROR, RESPONCE ERROR", url, -1)
  415. else
  416. global.L_DataRePort:ReportErrorModlistURL("MODLIST_URL_REQUEST_FAILED_PLANB", "-1001", "Request planb modlist URL ERROR, RESPONCE ERROR", url, -1)
  417. end
  418. if self._modlistURLIndex == 0 and self._modlistURLCount >= 3 then
  419. self:ReportError("[modlist][URL][1]网络不给力哦!点“确认”重试。", retry)
  420. -- 上报至服务器
  421. global.L_DataRePort:ReportErrorModlistURL("MODLIST_URL_REQUEST_FAILED", "-1001", "Request modlist URL ERROR, RESPONCE ERROR", url, code)
  422. else
  423. retry()
  424. end
  425. return nil
  426. end
  427. -- xxtea 解析
  428. response = self:decodeModlistXXTEA(response)
  429. -- json解析,检测是否解析成功
  430. local jsonData = self:decodeModlist(response)
  431. if not jsonData or not jsonData.data or #jsonData.data == 0 then
  432. if self._modlistURLIndex == 0 then --主域名
  433. global.L_DataRePort:ReportErrorModlistURL("MODLIST_URL_REQUEST_FAILED_MAIN", "-1002", "Request main modlist URL ERROR, JSON ERROR".. response, url, -1)
  434. else
  435. global.L_DataRePort:ReportErrorModlistURL("MODLIST_URL_REQUEST_FAILED_PLANB", "-1002", "Request planb modlist URL ERROR, JSON ERROR".. response, url, -1)
  436. end
  437. if self._modlistURLIndex == 0 then
  438. self:ReportError("[modlist][URL][2]远端服务器配置格式异常", retry)
  439. -- 上报至服务器
  440. global.L_DataRePort:ReportErrorModlistURL("MODLIST_URL_REQUEST_FAILED", "-1002", "Request modlist URL ERROR, JSON ERROR: " .. response, url, code)
  441. else
  442. retry()
  443. end
  444. return nil
  445. end
  446. self._modlistURLCount = 0
  447. self:RespModlistURL( jsonData )
  448. end
  449. local originUrl = (self._modlistURLIndex == 1 and self:GetModInfoURLPlanB() and self:GetModInfoURLPlanB() ~= "") and self:GetModInfoURLPlanB() or self:GetModInfoURL()
  450. local modInfoURL = string.format( originUrl, self:GetChannelID() )
  451. modInfoURL = modInfoURL .. "?" .. string.format("type=getaway&time=%s&sign=%s", os.time(), get_str_MD5("key="..self._modlistSignKey .. "&time="..os.time()))
  452. self._modlistURLIndex = 1-self._modlistURLIndex
  453. -- debug
  454. releasePrint( "mod list URL:", modInfoURL )
  455. if modInfoURL and string.len(modInfoURL) > 0 then
  456. HTTPRequest(modInfoURL, callback)
  457. ShowLoadingBar()
  458. end
  459. end
  460. function GameEnvManager:RespModlistURL(jsonData)
  461. local data = jsonData.data
  462. self._modlistURLList = data
  463. self:RequestModInfo()
  464. end
  465. function GameEnvManager:GetModlistCachePath()
  466. local fileUtil = cc.FileUtils:getInstance()
  467. local filename = self:AddModlistCacheNamePrefix("ResModlist.txt")
  468. local filePath = fileUtil:getWritablePath() .. filename
  469. return filePath
  470. end
  471. function GameEnvManager:CleanupLocalModlist()
  472. local fileUtil = cc.FileUtils:getInstance()
  473. local filePath = self:GetModlistCachePath()
  474. if fileUtil:isFileExist(filePath) then
  475. fileUtil:removeFile(filePath)
  476. end
  477. end
  478. function GameEnvManager:GetLocalRuntime()
  479. local fileUtil = cc.FileUtils:getInstance()
  480. local filePath = self:GetModlistCachePath()
  481. if not fileUtil:isFileExist(filePath) then
  482. return ""
  483. end
  484. local response = fileUtil:getDataFromFileEx(filePath)
  485. local jsonData = self:decodeModlist(response)
  486. if not jsonData then
  487. return ""
  488. end
  489. if not jsonData.runtime then
  490. return ""
  491. end
  492. return "runtime=" .. jsonData.runtime
  493. end
  494. function GameEnvManager:RequestModInfo()
  495. -- 重新请求, 需要请求地址
  496. local function errorRetry()
  497. self:RequestModlistURL()
  498. end
  499. -- 重新请求
  500. local function retry()
  501. self:RequestModInfo()
  502. end
  503. -- 数据异常
  504. if #self._modlistURLList == 0 then
  505. self:ReportError("[modlist][0]网络不给力哦!点“确认”重试。", errorRetry)
  506. -- 上报至服务器
  507. global.L_DataRePort:ReportErrorModlistURL("MODLIST_INFO_REQUEST_FAILED", "-2000", "Request modlist INFO ERROR, URL ERROR", "empty", 0)
  508. return
  509. end
  510. -- http数据请求回调
  511. local function callback(success, response, url, code)
  512. HideLoadingBar()
  513. -- 拉取失败
  514. if not success then
  515. if #self._modlistURLList == 0 then
  516. self:ReportError("[modlist][1]网络不给力哦!点“确认”重试。", errorRetry)
  517. -- 上报至服务器
  518. global.L_DataRePort:ReportErrorModlistURL("MODLIST_INFO_REQUEST_FAILED", "-2001", "Request modlist INFO ERROR, CODE ERROR", url, code)
  519. else
  520. retry()
  521. end
  522. return nil
  523. end
  524. -- 数据异常
  525. if not response then
  526. if #self._modlistURLList == 0 then
  527. self:ReportError("[modlist][2]网络不给力哦!点“确认”重试。", errorRetry)
  528. -- 上报至服务器
  529. global.L_DataRePort:ReportErrorModlistURL("MODLIST_INFO_REQUEST_FAILED", "-2002", "Request modlist INFO ERROR, RESPONSE ERROR", url, code)
  530. else
  531. retry()
  532. end
  533. return nil
  534. end
  535. -- xxtea 解析
  536. response = self:decodeModlistXXTEA(response)
  537. -- json解析,检测是否解析成功
  538. local jsonData = self:decodeModlist(response)
  539. if not jsonData then
  540. if #self._modlistURLList == 0 then
  541. self:CleanupLocalModlist()
  542. self:ReportError("[modlist][3]远端服务器配置格式异常", errorRetry)
  543. -- 上报至服务器
  544. global.L_DataRePort:ReportErrorModlistURL("MODLIST_INFO_REQUEST_FAILED", "-2003", "Request modlist INFO ERROR, JSON ERROR", url, code)
  545. else
  546. retry()
  547. end
  548. return nil
  549. end
  550. -- 本地是否是最新的
  551. local fileUtil = cc.FileUtils:getInstance()
  552. local filePath = ""
  553. if jsonData.latestData then
  554. -- 读取本地,json解析
  555. filePath = self:GetModlistCachePath()
  556. response = fileUtil:getDataFromFileEx(filePath)
  557. jsonData = self:decodeModlist(response)
  558. else
  559. -- 不是最新,保存内容至本地,无需再次解析json
  560. filePath = self:GetModlistCachePath()
  561. if fileUtil:isFileExist(filePath) then
  562. fileUtil:removeFile(filePath)
  563. end
  564. fileUtil:writeStringToFile(response, filePath)
  565. end
  566. -- json解析,检测是否解析成功
  567. if not jsonData then
  568. if #self._modlistURLList == 0 then
  569. self:CleanupLocalModlist()
  570. self:ReportError("[modlist][4]远端服务器配置格式异常", errorRetry)
  571. -- 上报至服务器
  572. global.L_DataRePort:ReportErrorModlistURL("MODLIST_INFO_REQUEST_FAILED", "-2004", "Request modlist INFO ERROR, JSON ERROR", url, code)
  573. else
  574. retry()
  575. end
  576. return nil
  577. end
  578. self:parseModList( jsonData )
  579. end
  580. local randomIdx = math.random(1, #self._modlistURLList)
  581. local modlistURL = table.remove(self._modlistURLList, randomIdx)
  582. local modInfoURL = string.format( modlistURL, self:GetChannelID() )
  583. local modInfoData = modInfoURL
  584. modInfoData = string.gsub(modInfoData, "http://", "")
  585. modInfoData = string.gsub(modInfoData, "https://", "")
  586. modInfoData = string.gsub(modInfoData, "/gsl/auth/mod_list_auth", "")
  587. modInfoData = string.gsub(modInfoData, "/gsl/main", "")
  588. local s = string.find(modInfoData, "/")
  589. modInfoData = string.sub(modInfoData, s+1, string.len(modInfoData))
  590. local signKey = self:GetModlistSignKey()
  591. local timestamp = os.time()
  592. local sign = get_str_MD5("data=" .. modInfoData .. "&key=" .. signKey .. "&time="..timestamp)
  593. -- modInfoURL = modInfoURL .. "?" .. self:GetLocalRuntime()
  594. modInfoURL = modInfoURL .. string.format("?time=%s&sign=%s", timestamp, sign)
  595. -- debug
  596. releasePrint( "mod info URL:", modInfoURL )
  597. if modInfoURL and string.len(modInfoURL) > 0 then
  598. HTTPRequest(modInfoURL, callback)
  599. ShowLoadingBar()
  600. end
  601. end
  602. function GameEnvManager:parseModList(jsonData)
  603. dump(jsonData)
  604. -- 根据modlist中 platformId 更新本地的 channelID
  605. if jsonData.platformId and tostring(jsonData.platformId) ~= "" then
  606. self:SetChannelID(tostring(jsonData.platformId))
  607. end
  608. -- native notice
  609. global.L_NativeBridgeManager:GN_LoadModlistFinish()
  610. -- apk强更版本检查
  611. if jsonData.apkVerUrl then
  612. local url = {}
  613. url.apkVerUrl = jsonData.apkVerUrl .. jsonData.resVer
  614. global.L_NativeBridgeManager:GN_checkApkUpdate(url)
  615. end
  616. -- apk强更版本检查 根据包名
  617. if jsonData.apkNameVerUrl and global.isAndroid then
  618. local packageName = self:GetAPKPackageName()
  619. local apkVerUrl = string.format("%s%s.json?v=%s",jsonData.apkNameVerUrl, packageName, os.time())
  620. self:SetAPKUpdateInfoUrl(apkVerUrl)
  621. end
  622. if jsonData.refer then
  623. global.L_ModuleManager:SetReferModuleID(jsonData.refer)
  624. end
  625. if jsonData.customData then
  626. self:SetModlistCustomData(jsonData.customData)
  627. end
  628. if jsonData.modData then
  629. global.L_ModuleManager:InitModules(jsonData.modData)
  630. end
  631. if jsonData.resVer then
  632. self:SetResVersion(jsonData.resVer)
  633. end
  634. if jsonData.loadingimg then
  635. self:SetGMLoadingData(jsonData.loadingimg)
  636. if jsonData.loadingimg.bar_carousel then
  637. global.L_ModuleManager:InitImagePre(jsonData.loadingimg.bar_carousel)
  638. end
  639. end
  640. -- 审核服检测
  641. local reviewVersion = jsonData.reviewVersion
  642. local versionCode = self:GetAPKVersionCode()
  643. if versionCode and reviewVersion then
  644. versionCode = tostring(versionCode)
  645. reviewVersion = tostring(reviewVersion)
  646. local reviewTable = string.split(reviewVersion, ",")
  647. for _, version in ipairs(reviewTable) do
  648. if versionCode == version then
  649. self:SetIsReview(true)
  650. break
  651. end
  652. end
  653. end
  654. if self:checkReview() then
  655. -- restart
  656. return
  657. end
  658. -- 安卓/ios 分平台读取
  659. local resURL = jsonData.resURL
  660. local resURL_win = jsonData.resURL_win
  661. local resURL_ios = jsonData.resURL_ios
  662. local resURL_ad = jsonData.resURL_ad
  663. resURL_ios = (resURL_ios and resURL_ios ~= "") and resURL_ios or resURL
  664. resURL_ad = (resURL_ad and resURL_ad ~= "") and resURL_ad or resURL
  665. resURL_win = (resURL_win and resURL_win ~= "") and resURL_win or resURL_ad
  666. --备份cdn
  667. local resURL2 = jsonData.resURL2
  668. local resURL_win2 = jsonData.resURL_win2
  669. local resURL_ios2 = jsonData.resURL_ios2
  670. local resURL_ad2 = jsonData.resURL_ad2
  671. resURL_ios2 = (resURL_ios2 and resURL_ios2 ~= "") and resURL_ios2 or resURL2
  672. resURL_ad2 = (resURL_ad2 and resURL_ad2 ~= "") and resURL_ad2 or resURL2
  673. resURL_win2 = (resURL_win2 and resURL_win2 ~= "") and resURL_win2 or resURL_ad2
  674. if global.isWindows then
  675. resURL = resURL_win
  676. resURL2 = resURL_win2
  677. elseif global.isAndroid or global.isOHOS then
  678. resURL = resURL_ad
  679. resURL2 = resURL_ad2
  680. elseif global.isIOS then
  681. resURL = resURL_ios
  682. resURL2 = resURL_ios2
  683. end
  684. if (resURL and string.len(resURL) > 0) or (resURL2 and string.len(resURL2) > 0) then
  685. self._updateCount = 0
  686. self:SetRootDomain(resURL)
  687. self:SetRootDomain2(resURL2)
  688. self:SetLauncherUrlSuffix(jsonData.urlsuffix)
  689. if not self:IsReview() then
  690. self:CheckUpdate()
  691. else
  692. self:handleAlreadyUpToDate()
  693. end
  694. else
  695. self:ReportError("远程资源路径未发现!")
  696. end
  697. -- 新安装包地址
  698. self:CheckNewPackage(jsonData.currpackage)
  699. end
  700. ---------------------------------- mod info ------------------------------------
  701. ---------------------------------- hot update ------------------------------------
  702. function GameEnvManager:CleanupDownloader()
  703. if self._downloader then
  704. self._downloader:Cleanup()
  705. self._downloader = nil
  706. end
  707. end
  708. function GameEnvManager:CleanupDownloaderSchedule()
  709. if self._launcherUpdateSchedule then
  710. global.Scheduler:unscheduleScriptEntry(self._launcherUpdateSchedule)
  711. self._launcherUpdateSchedule = nil
  712. end
  713. end
  714. function GameEnvManager:handleUpdateFinished()
  715. self:CleanupDownloader()
  716. self:CleanupDownloaderSchedule()
  717. local restartMode = nil
  718. if global.Platform == cc.PLATFORM_OS_ANDROID then
  719. local checkNativeFiles = {
  720. "libMyGame.so.new",
  721. }
  722. local fileUtil = cc.FileUtils:getInstance()
  723. local writePath = fileUtil:getWritablePath()
  724. for _, value in ipairs( checkNativeFiles ) do
  725. if fileUtil:isFileExist( value ) then
  726. restartMode = "code"
  727. break
  728. end
  729. end
  730. end
  731. self:RestartGame( restartMode )
  732. end
  733. function GameEnvManager:handleAlreadyUpToDate()
  734. global.L_LoadingManager:CloseLayer()
  735. self:CleanupDownloader()
  736. self:CleanupDownloaderSchedule()
  737. global.L_ModuleChooseManager:OnAlreadyUpToDate()
  738. -- native notice
  739. global.L_NativeBridgeManager:GN_LoadLauncherModeFinish()
  740. -- YD
  741. global.L_NativeBridgeManager:GN_requestInitYD(self:GetModlistCustomData())
  742. -- SDK login
  743. global.L_NativeBridgeManager:GN_accountLogin()
  744. -- download loading img
  745. local loadingData = global.L_GameEnvManager:GetGMLoadingData()
  746. if loadingData and loadingData.bg_name and loadingData.bg_url then
  747. global.L_GameEnvManager:downloadResEasy(loadingData.bg_url, loadingData.bg_name, function(isOK, filename)
  748. releasePrint("download", isOK, loadingData.bg_url, loadingData.bg_name)
  749. end)
  750. end
  751. if loadingData and loadingData.bar_bg_name and loadingData.bar_bg_url then
  752. global.L_GameEnvManager:downloadResEasy(loadingData.bar_bg_url, loadingData.bar_bg_name, function(isOK, filename)
  753. releasePrint("download", isOK, loadingData.bar_bg_url, loadingData.bar_bg_name)
  754. end)
  755. end
  756. if loadingData and loadingData.bar_name and loadingData.bar_url then
  757. global.L_GameEnvManager:downloadResEasy(loadingData.bar_url, loadingData.bar_name, function(isOK, filename)
  758. releasePrint("download", isOK, loadingData.bar_url, loadingData.bar_name)
  759. end)
  760. end
  761. --获取pc端的versiconCode
  762. if global.isWindows then
  763. if Win32BridgeCtl and Win32BridgeCtl.Inst and Win32BridgeCtl:Inst().GetPcVersionCode then
  764. self.apkVersionCode = Win32BridgeCtl:Inst():GetPcVersionCode()
  765. end
  766. releasePrint("pc VersionCode = "..self.apkVersionCode)
  767. end
  768. end
  769. function GameEnvManager:CheckUpdate()
  770. local module = global.L_ModuleManager:GetLauncherModule()
  771. if not module then
  772. releasePrint( "can not find launcher module!!" )
  773. return false
  774. end
  775. if self._downloader then
  776. releasePrint("Launcher pulling!!!")
  777. return false
  778. end
  779. local function versionCompare(str1, str2)
  780. if str1 == "999.1.1" then
  781. -- 内网测试版本
  782. return 1
  783. end
  784. if str1 ~= str2 then
  785. return -1
  786. end
  787. return 1
  788. end
  789. local downloader = AssetsManager:new()
  790. downloader:SetEventDelegate( self )
  791. downloader:SetVersionCompareHandle(versionCompare)
  792. local modulePath = module:GetPath()
  793. local moduleID = module:GetID()
  794. local localVersionName = module:GetVersionFileName()
  795. local localManifestName = module:GetManifestFileName()
  796. local storagePath = cc.FileUtils:getInstance():getWritablePath() .. modulePath
  797. local tempManifestName = "project.manifest.temp"
  798. local tempDirName = "/_temp"
  799. local rootDomain = self._updateCount == 0 and self:GetRootDomain() or self:GetRootDomain2()
  800. local resUrl = string.format( "%s%s", rootDomain, tostring(module:GetRemotePath(self:GetLauncherUrlSuffix())) )
  801. local manifestUrl = resUrl .. localManifestName
  802. local versionUrl = resUrl .. localVersionName
  803. local resVersion = self:GetResVersion()
  804. local jobs = 2
  805. local ignoreLocal = not global.FileUtilCtl:isFileExist( localManifestName )
  806. -- verbose
  807. releasePrint( "-------------------------------------------------------------" )
  808. releasePrint( "pull module:", moduleID )
  809. releasePrint( manifestUrl )
  810. releasePrint( versionUrl )
  811. releasePrint( "ignore local:" .. tostring(ignoreLocal) )
  812. releasePrint( "local storage path:" .. tostring(storagePath) )
  813. releasePrint( "-------------------------------------------------------------" )
  814. -- request download
  815. local ret = downloader:DownLoadRequest( "launcher_update", localManifestName, storagePath, tempManifestName, tempDirName,
  816. resUrl, manifestUrl, versionUrl, resVersion, jobs, ignoreLocal )
  817. if not ret then
  818. downloader:Cleanup()
  819. return false
  820. end
  821. self._downloader = downloader
  822. if self._updateCount == 0 and self:GetRootDomain2() and string.len(self:GetRootDomain2()) > 0 then
  823. self._launcherUpdateSchedule = PerformWithDelayGlobal(function ()
  824. self._launcherUpdateSchedule = nil
  825. self._updateCount = self._updateCount + 1
  826. self:CleanupDownloader()
  827. self:CheckUpdate()
  828. end, 10)
  829. else
  830. self._launcherUpdateSchedule = PerformWithDelayGlobal(function ()
  831. self._launcherUpdateSchedule = nil
  832. -- 触发重新下载
  833. local moduleID = global.L_ModuleManager:GetLauncherModuleID()
  834. local moduleVersion = self:GetLauncherUrlSuffix()
  835. local errorString = string.format("[%s][%s]远程清单访问超时!\n点击下方\"确认\"重试", tostring(moduleID), tostring(moduleVersion))
  836. local function callback()
  837. self._updateCount = 0
  838. self:CleanupDownloader()
  839. self:CheckUpdate()
  840. end
  841. self:ReportError(errorString, callback)
  842. end, 10)
  843. end
  844. return true
  845. end
  846. function GameEnvManager:onLocalManifestError()
  847. RecordBuglyLogIm( Tags, "Local Manifest Error!" )
  848. self:CleanupDownloader()
  849. self:CleanupDownloaderSchedule()
  850. if self._updateCount == 0 and self:GetRootDomain2() and string.len(self:GetRootDomain2()) > 0 then
  851. self._updateCount = self._updateCount + 1
  852. self:CheckUpdate()
  853. else
  854. -- 触发重新下载
  855. local moduleID = global.L_ModuleManager:GetLauncherModuleID()
  856. local moduleVersion = self:GetLauncherUrlSuffix()
  857. local errorString = string.format("[%s][%s]远程清单异常!\n点击下方\"确认\"重试", tostring(moduleID), tostring(moduleVersion))
  858. local function callback()
  859. self._updateCount = 0
  860. self:CheckUpdate()
  861. end
  862. self:ReportError(errorString, callback)
  863. end
  864. end
  865. function GameEnvManager:onRemoteManifestError()
  866. RecordBuglyLogIm( Tags, "Remote Manifest Error!" )
  867. self:CleanupDownloader()
  868. self:CleanupDownloaderSchedule()
  869. if self._updateCount == 0 and self:GetRootDomain2() and string.len(self:GetRootDomain2()) > 0 then
  870. self._updateCount = self._updateCount + 1
  871. self:CheckUpdate()
  872. else
  873. -- 触发重新下载
  874. local moduleID = global.L_ModuleManager:GetLauncherModuleID()
  875. local moduleVersion = self:GetLauncherUrlSuffix()
  876. local errorString = string.format("[%s][%s]远程清单异常!\n点击下方\"确认\"重试", tostring(moduleID), tostring(moduleVersion))
  877. local function callback()
  878. self._updateCount = 0
  879. self:CheckUpdate()
  880. end
  881. self:ReportError(errorString, callback)
  882. end
  883. end
  884. function GameEnvManager:onCheckVersionInfo()
  885. self:CleanupDownloaderSchedule()
  886. global.L_LoadingManager:OpenLayer({isCheckVersion=true, delay=true})
  887. end
  888. function GameEnvManager:onNewVersion( versionSize )
  889. self:CleanupDownloaderSchedule()
  890. local sizeInMB = versionSize / (1024 * 1024)
  891. RecordBuglyLogIm( Tags, "New Version Found:" .. tostring( sizeInMB ) )
  892. global.L_LoadingManager:CloseLayer()
  893. global.L_LoadingManager:OpenLayer({isCheckVersion=true})
  894. if self._downloader then
  895. global.L_LoadingManager:CloseLayer()
  896. global.L_LoadingManager:OpenLayer()
  897. self._downloader:StartUpdate()
  898. end
  899. end
  900. function GameEnvManager:onAlreadyUpToDate()
  901. RecordBuglyLogIm( Tags, "Already Up To Date")
  902. self:CleanupDownloaderSchedule()
  903. local launcherModule = global.L_ModuleManager:GetLauncherModule()
  904. if self._downloader and launcherModule then
  905. local version = self._downloader:GetRemoteManifestVer()
  906. launcherModule:SetRemoteVersion( version )
  907. end
  908. self:handleAlreadyUpToDate()
  909. end
  910. function GameEnvManager:onUpdatePercent( percent )
  911. self:CleanupDownloaderSchedule()
  912. global.L_LoadingManager:UpdatePercent(percent)
  913. end
  914. function GameEnvManager:onAssetError( assetID, msg )
  915. self:CleanupDownloaderSchedule()
  916. RecordBuglyLogIm( Tags, "Asset Error! " .. tostring( assetID ) )
  917. end
  918. function GameEnvManager:onDownloadFinished()
  919. RecordBuglyLogIm( Tags, "Update Finished" )
  920. self:CleanupDownloaderSchedule()
  921. self:handleUpdateFinished()
  922. global.L_LoadingManager:CloseLayer()
  923. end
  924. function GameEnvManager:onDownloadFailed()
  925. RecordBuglyLogIm( Tags, "Update Failed!" )
  926. self:CleanupDownloaderSchedule()
  927. if self._downloader then
  928. self._downloader:Retry()
  929. end
  930. end
  931. ---------------------------------- hot update ------------------------------------
  932. function GameEnvManager:RestartGame( mode )
  933. global.L_LoadingBarManager:CloseLayer()
  934. global.L_ModuleChooseManager:CloseLayer()
  935. global.L_GameLayerManager:Close()
  936. -- cleanup user data
  937. UserData:Cleanup()
  938. UserData:setVersionPath("")
  939. local director = cc.Director:getInstance()
  940. local texCache = director:getTextureCache()
  941. -- clearAsyncCallback
  942. texCache:unbindAllImageAsync()
  943. -- clear cocos2d cache, issue: release res maybe crash.
  944. director:purgeCachedData()
  945. -- clear cocos2d event
  946. director:getEventDispatcher():removeAllEventListeners()
  947. -- clear cocos2d scheduler, but system scheduler( ActionManager )
  948. director:getScheduler():unscheduleAllWithMinPriority( cc.PRIORITY_NON_SYSTEM_MIN )
  949. -- clear cocos2d action
  950. director:getActionManager():removeAllActions()
  951. -- clear cocos2d audio
  952. cc.SimpleAudioEngine:destroyInstance()
  953. ccexp.AudioEngine:uncacheAll()
  954. -- ccexp.AudioEngine:endToLua()
  955. -- destroy glProgram
  956. cc.GLProgramCache:destroyInstance()
  957. -- reset downloader
  958. httpDownloader:Inst():reset()
  959. -- record log
  960. local platform = cc.Application:getInstance():getTargetPlatform()
  961. if platform == cc.PLATFORM_OS_ANDROID then
  962. if nil ~= mode then
  963. local jData = {}
  964. jData.restartMode = mode
  965. global.L_NativeBridgeManager:GN_restartGame(jData)
  966. else
  967. buglyLog( 0, "restart game", "Restart Lua VM!" )
  968. end
  969. end
  970. releasePrint( "Restart Launcher completed" )
  971. releasePrint( "Restart Lua VM!" )
  972. -- restart luaVM
  973. LuaBridgeCtl:Inst():CreateNewState()
  974. end
  975. ---------------------------------- overlay install ------------------------------------
  976. function GameEnvManager:CheckAppOverlayTrace()
  977. local lastAppVerCode = tonumber( self:readAppOverlayTrace() )
  978. local currAppVerCode = tonumber( self:GetAPKVersionCode() )
  979. if currAppVerCode and lastAppVerCode and currAppVerCode > lastAppVerCode then
  980. self:onAppOverlay()
  981. self:writeAppOverlayTrace( currAppVerCode )
  982. self:RestartGame()
  983. end
  984. end
  985. function GameEnvManager:readAppOverlayTrace()
  986. local fileUtil = cc.FileUtils:getInstance()
  987. local writePath = fileUtil:getWritablePath()
  988. local filePath = writePath .. AppOverlayTraceFile
  989. local appVerCode = tonumber( self:GetAPKVersionCode() )
  990. if not fileUtil:isFileExist( filePath ) then
  991. self:writeAppOverlayTrace( appVerCode )
  992. return appVerCode
  993. end
  994. local fileContent = fileUtil:getDataFromFile( filePath )
  995. local tmpCode = tonumber( fileContent )
  996. if nil == tmpCode then
  997. self:writeAppOverlayTrace( appVerCode )
  998. return appVerCode
  999. else
  1000. appVerCode = tmpCode
  1001. end
  1002. return appVerCode
  1003. end
  1004. function GameEnvManager:writeAppOverlayTrace( appVerCode )
  1005. local fileUtil = cc.FileUtils:getInstance()
  1006. local writePath = fileUtil:getWritablePath()
  1007. local filePath = writePath .. AppOverlayTraceFile
  1008. fileUtil:writeStringToFile( tostring( appVerCode ), filePath )
  1009. end
  1010. function GameEnvManager:onAppOverlay()
  1011. -- 处理盒子覆盖安装清理launcher导致进入游戏黑屏的问题
  1012. if global.L_GameEnvManager:GetEnvDataByKey("isBoxLogin") == 1 then
  1013. release_print("box not clear launcher1")
  1014. return nil
  1015. end
  1016. local removeDirs = {}
  1017. local removeFiles = {}
  1018. if( cc.PLATFORM_OS_IPHONE == global.Platform ) or ( cc.PLATFORM_OS_IPAD == global.Platform ) then
  1019. removeDirs = {
  1020. "mod_launcher",
  1021. "mod_fgcq",
  1022. }
  1023. removeFiles = {
  1024. }
  1025. else
  1026. removeDirs = {
  1027. "mod_launcher",
  1028. "mod_fgcq",
  1029. }
  1030. removeFiles = {
  1031. "libMyGame.so",
  1032. }
  1033. end
  1034. local fileUtil = cc.FileUtils:getInstance()
  1035. local writePath = fileUtil:getWritablePath()
  1036. -- remove dirs
  1037. for _, value in ipairs( removeDirs ) do
  1038. -- debug
  1039. releasePrint( "remove dir:" .. writePath .. value )
  1040. fileUtil:removeDirectory( writePath .. value )
  1041. end
  1042. -- remove files
  1043. for _, value in ipairs( removeFiles ) do
  1044. -- debug
  1045. releasePrint( "remove file:" .. writePath .. value )
  1046. fileUtil:removeFile( writePath .. value )
  1047. end
  1048. end
  1049. ---------------------------------- overlay install ------------------------------------
  1050. function GameEnvManager:CheckRootDir()
  1051. local fileUtil = cc.FileUtils:getInstance()
  1052. local writePath = fileUtil:getWritablePath()
  1053. local checkDirs = {
  1054. writePath,
  1055. }
  1056. for _, value in ipairs( checkDirs ) do
  1057. if not fileUtil:isDirectoryExist( value ) then
  1058. releasePrint( "create root dir:", value )
  1059. fileUtil:createDirectory( value )
  1060. end
  1061. end
  1062. if global.isIOS then
  1063. -- check ios root dir
  1064. local iosRootDir = fileUtil:getWritablePath() .. "/files/"
  1065. if not fileUtil:isDirectoryExist(iosRootDir) then
  1066. releasePrint("create ios root dir")
  1067. fileUtil:createDirectory(iosRootDir)
  1068. end
  1069. end
  1070. end
  1071. function GameEnvManager:CheckNewPackage(packageData)
  1072. if not packageData or not packageData.url or not packageData.currVersion then
  1073. return
  1074. end
  1075. local versionCode = tonumber(self:GetAPKVersionCode())
  1076. local currVersion = tonumber(packageData.currVersion)
  1077. local tips = packageData.tips or "检测到新版本,请点击\"确认\"前往下载"
  1078. local url = packageData.url
  1079. release_print("CheckNewPackage", currVersion, versionCode, url)
  1080. -- 版本号合法
  1081. if not currVersion or not versionCode then
  1082. return
  1083. end
  1084. -- 版本已经是最新
  1085. if versionCode >= currVersion then
  1086. return
  1087. end
  1088. local tipsData = {
  1089. btnType = 1,
  1090. str = tips,
  1091. callback = function()
  1092. cc.Application:getInstance():openURL(url)
  1093. self:RestartGame()
  1094. end
  1095. }
  1096. global.L_CommonTipsManager:OpenLayer( tipsData )
  1097. end
  1098. ---------------------------------- game env ------------------------------------
  1099. function GameEnvManager:SetEnvData(data)
  1100. self._envData = data
  1101. end
  1102. function GameEnvManager:GetEnvData()
  1103. return self._envData
  1104. end
  1105. function GameEnvManager:SetEnvDataByKey(key, value)
  1106. self._envData[key] = value
  1107. end
  1108. function GameEnvManager:GetEnvDataByKey(key)
  1109. return self._envData[key]
  1110. end
  1111. function GameEnvManager:SetLauncherSrvID(srvid)
  1112. self._launcherSrvID = srvid
  1113. end
  1114. function GameEnvManager:GetLauncherSrvID(srvid)
  1115. return self._launcherSrvID
  1116. end
  1117. function GameEnvManager:SetLauncherWhitelist(whitelist)
  1118. self._launcherWhitelist = whitelist
  1119. end
  1120. function GameEnvManager:GetLauncherWhitelist()
  1121. return self._launcherWhitelist
  1122. end
  1123. -- 加载开关配置 switchConfig.json
  1124. function GameEnvManager:LoadSwitchConfig()
  1125. local fileUtil = cc.FileUtils:getInstance()
  1126. local filename = "switchConfig.json"
  1127. local isExist = fileUtil:isFileExist(filename)
  1128. if not isExist then
  1129. return
  1130. end
  1131. -- 是否有内容
  1132. local jsonStr = nil
  1133. if fileUtil:isFileExist(filename) then
  1134. jsonStr = fileUtil:getDataFromFileEx(filename)
  1135. elseif fileUtil:isFileExist(filenameT) then
  1136. jsonStr = fileUtil:getDataFromFileEx(filenameT)
  1137. end
  1138. if not jsonStr or jsonStr == "" then
  1139. return nil
  1140. end
  1141. -- 是否是json
  1142. local jsonData = cjson.decode(jsonStr)
  1143. if not jsonData then
  1144. return nil
  1145. end
  1146. -- 保存
  1147. for k,v in pairs(jsonData) do
  1148. self._envData[k] = v
  1149. end
  1150. if jsonData["showLanguage"] then
  1151. loadLanguageConfig( jsonData["showLanguage"] )
  1152. end
  1153. end
  1154. function GameEnvManager:LoadGameEnv()
  1155. local fileUtil = cc.FileUtils:getInstance()
  1156. local filename = "env.json"
  1157. local filenameT = "env.json.tmp"
  1158. local isExist = fileUtil:isFileExist(filename) or fileUtil:isFileExist(filenameT)
  1159. -- 是否存在
  1160. if not isExist then
  1161. if global.isDebugMode or global.isGMMode then
  1162. -- 开发模式下,给默认渠道号
  1163. self:SetChannelID(defaultChannelID)
  1164. self:SetGMName("1")
  1165. global.CURRENT_OPERMODE = global.OPERMODE_MOBILE
  1166. end
  1167. return nil
  1168. end
  1169. -- 是否有内容
  1170. local jsonStr = nil
  1171. if fileUtil:isFileExist(filename) then
  1172. jsonStr = fileUtil:getDataFromFileEx(filename)
  1173. elseif fileUtil:isFileExist(filenameT) then
  1174. jsonStr = fileUtil:getDataFromFileEx(filenameT)
  1175. end
  1176. if not jsonStr or jsonStr == "" then
  1177. self._launchERROR = true
  1178. return nil
  1179. end
  1180. -- 是否是json
  1181. local jsonData = cjson.decode(jsonStr)
  1182. if not jsonData then
  1183. self._launchERROR = true
  1184. return nil
  1185. end
  1186. -- 存储
  1187. for k,v in pairs(jsonData) do
  1188. self._envData[k] = v
  1189. end
  1190. -- 開發模式/GM模式
  1191. if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_WINDOWS and (global.isDebugMode or global.isGMMode) then
  1192. -- 操作模式
  1193. local oper_mode = tonumber(jsonData.oper_mode) or 2
  1194. global.CURRENT_OPERMODE = oper_mode
  1195. end
  1196. -- 分辨率
  1197. if global.CURRENT_OPERMODE == global.OPERMODE_WINDOWS then
  1198. -- 竖版
  1199. local isPortrait = tonumber(jsonData.isPortrait) == 1
  1200. if isPortrait then
  1201. global.IS_PORTRAIT = true
  1202. end
  1203. local defaultReslution = isPortrait and "640x980" or "1024x768"
  1204. local resolution = jsonData.resolution or defaultReslution
  1205. if isPortrait then
  1206. resolution = defaultReslution
  1207. end
  1208. local slices = string.split(resolution, "x")
  1209. local resolutionWidth = tonumber(slices[1]) or 1024
  1210. local resolutionHeight = tonumber(slices[2]) or 768
  1211. global.DesignSize_Win = {width = resolutionWidth, height = resolutionHeight}
  1212. global.DeviceSize_Win = {width = resolutionWidth, height = resolutionHeight}
  1213. releasePrint(global.DeviceSize_Win.width, global.DeviceSize_Win.height)
  1214. end
  1215. -- modlist
  1216. if jsonData.modlist and string.len(jsonData.modlist) > 0 then
  1217. self:SetModInfoURL(jsonData.modlist)
  1218. end
  1219. if jsonData.modlistPlanB and string.len(jsonData.modlistPlanB) > 0 then
  1220. self:SetModInfoURLPlanB(jsonData.modlistPlanB)
  1221. end
  1222. -- 渠道ID
  1223. self:SetChannelID(jsonData.channel)
  1224. -- 推广员标识
  1225. self:SetGMName(jsonData.gm)
  1226. -- signkey
  1227. self:SetSignkey(jsonData.signkey)
  1228. -- server id
  1229. if jsonData.serverId and string.len(jsonData.serverId) > 0 then
  1230. self:SetLauncherSrvID(jsonData.serverId)
  1231. end
  1232. -- whitelist
  1233. if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_WINDOWS then
  1234. if jsonData.whitelist and string.len(jsonData.whitelist) > 0 then
  1235. self:SetLauncherWhitelist(tonumber(jsonData.whitelist) == 1)
  1236. end
  1237. end
  1238. -- gm res search path
  1239. if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_WINDOWS then
  1240. if jsonData.gmRes and string.len(jsonData.gmRes) > 0 then
  1241. self:SetGMSearchPath(jsonData.gmRes)
  1242. -- 新增GM资源搜索目录
  1243. local rootPath = global.FileUtilCtl:getDefaultResourceRootPath()
  1244. local gmCachePath = rootPath .. "gm_cache/" .. self:GetGMSearchPath() .. "/"
  1245. self:SetGMCachePath(gmCachePath)
  1246. global.FileUtilCtl:addSearchPath(gmCachePath)
  1247. end
  1248. end
  1249. -- 映射功能只在windows生效
  1250. if global.isWindows then
  1251. global.FileUtilCtl:setFilenameLookupDictionary({})
  1252. end
  1253. self:LoadSwitchConfig()
  1254. end
  1255. function GameEnvManager:SetGameEnvDataByKey(key, value)
  1256. -- windows only
  1257. local showResolution = global.L_GameEnvManager:GetEnvDataByKey("showResolution")
  1258. if global.isDebugMode or global.isGMMode or showResolution then
  1259. if type(key) ~= "string" then
  1260. print("STRING ONLY")
  1261. return nil
  1262. end
  1263. local module = global.L_ModuleManager:GetLauncherModule()
  1264. if not module then
  1265. releasePrint( "can not find launcher module!!" )
  1266. return false
  1267. end
  1268. local fileUtil = cc.FileUtils:getInstance()
  1269. local storagePath = cc.FileUtils:getInstance():getDefaultResourceRootPath() .. "env.json"
  1270. local jsonData = {}
  1271. local jsonStr = fileUtil:getDataFromFileEx("env.json")
  1272. if not jsonStr or jsonStr == "" or jsonStr == "env.json" then
  1273. jsonData = {}
  1274. else
  1275. jsonData = cjson.decode(jsonStr)
  1276. end
  1277. jsonData = jsonData or {}
  1278. jsonData[key] = value
  1279. jsonData["channel"] = self:GetChannelID()
  1280. jsonData["gm"] = self:GetGMName() or "21"
  1281. local jsonStr = cjson.encode(jsonData)
  1282. fileUtil:writeStringToFile(jsonStr, storagePath)
  1283. end
  1284. end
  1285. function GameEnvManager:SetGamePreEnvDataByKey(key, value)
  1286. local showResolution = global.L_GameEnvManager:GetEnvDataByKey("showResolution")
  1287. if global.isDebugMode or global.isGMMode or showResolution then
  1288. if type(key) ~= "string" then
  1289. print("STRING ONLY")
  1290. return nil
  1291. end
  1292. local module = global.L_ModuleManager:GetLauncherModule()
  1293. if not module then
  1294. releasePrint( "can not find launcher module!!" )
  1295. return false
  1296. end
  1297. local fileUtil = cc.FileUtils:getInstance()
  1298. local storagePath = cc.FileUtils:getInstance():getDefaultResourceRootPath() .. "preenv.json"
  1299. if fileUtil:isFileExist(storagePath) then
  1300. local jsonData = {}
  1301. local jsonStr = fileUtil:getDataFromFileEx("preenv.json")
  1302. if not jsonStr or jsonStr == "" or jsonStr == "preenv.json" then
  1303. jsonData = {}
  1304. else
  1305. jsonData = cjson.decode(jsonStr)
  1306. end
  1307. jsonData = jsonData or {}
  1308. jsonData[key] = value
  1309. local jsonStr = cjson.encode(jsonData)
  1310. fileUtil:writeStringToFile(jsonStr, storagePath)
  1311. end
  1312. end
  1313. end
  1314. function GameEnvManager:downloadResEasy(resUrl, filename, downloadCB)
  1315. -- check param
  1316. if not resUrl or string.len(resUrl) == 0 then
  1317. downloadCB(false, filename)
  1318. return
  1319. end
  1320. -- check param
  1321. if not filename or string.len(filename) == 0 then
  1322. downloadCB(false, filename)
  1323. return
  1324. end
  1325. local directoryPath = global.FileUtilCtl:getWritablePath()
  1326. local filePath = directoryPath .. filename
  1327. print("filePath", filePath, global.FileUtilCtl:isFileExist(filePath) )
  1328. -- remove cache
  1329. local textureCache = global.Director:getTextureCache()
  1330. if textureCache:getTextureForKey(filePath) then
  1331. textureCache:removeTextureForKey(filePath)
  1332. end
  1333. -- is exist
  1334. if global.FileUtilCtl:isFileExist(filePath) then
  1335. downloadCB(true, filename)
  1336. return
  1337. end
  1338. local downloader = httpDownloader:Inst()
  1339. downloader:AsyncDownloadEasy(resUrl, filePath,
  1340. function(isOK)
  1341. print("downloadRes isOK", isOK)
  1342. -- 下载成功了
  1343. if isOK then
  1344. if self._isGameSuspend then
  1345. table.insert(self._suspendCBCache, function()
  1346. downloadCB(isOK, filename)
  1347. end)
  1348. else
  1349. downloadCB(isOK, filename)
  1350. end
  1351. return
  1352. end
  1353. -- 下载失败了
  1354. -- 重试 3 次
  1355. self._downloadEasyCount[filename] = self._downloadEasyCount[filename] or 0
  1356. self._downloadEasyCount[filename] = self._downloadEasyCount[filename] + 1
  1357. if self._downloadEasyCount[filename] <= 3 then
  1358. global.L_GameEnvManager:downloadResEasy(resUrl, filename, downloadCB)
  1359. end
  1360. end,
  1361. 0
  1362. )
  1363. end
  1364. function GameEnvManager:StartGame()
  1365. if not global.L_GameLayerManager._uiNode then
  1366. self:LoadGameInfo()
  1367. return
  1368. end
  1369. local filepath = self.startPath
  1370. local viewSize = global.Director:getVisibleSize()
  1371. local SplashTime = 1.0
  1372. local SplashFadeInTime = 0.6
  1373. local SplashFadeOutTime = 0.8
  1374. local layer = cc.Layer:create()
  1375. global.L_GameLayerManager._uiNode:addChild(layer, 999)
  1376. -- swallow
  1377. local layout = ccui.Layout:create()
  1378. layer:addChild(layout)
  1379. layout:setBackGroundColor(cc.c3b(0, 0, 0))
  1380. layout:setBackGroundColorType(1)
  1381. layout:setBackGroundColorOpacity(255)
  1382. layout:setContentSize({width = viewSize.width, height = viewSize.height})
  1383. layout:setTouchEnabled(true)
  1384. ----------------------------------------
  1385. ----------------------------------------
  1386. ----------------------------------------
  1387. local function finishCB()
  1388. -- native notice
  1389. global.L_NativeBridgeManager:GN_LoadGameInfo()
  1390. layer:removeFromParent()
  1391. self:LoadGameInfo()
  1392. end
  1393. -- 闪屏
  1394. local function startSplash()
  1395. -- played
  1396. if LuaBridgeCtl:Inst():GetModulesSwitch(8) == 1 then
  1397. finishCB()
  1398. return
  1399. end
  1400. LuaBridgeCtl:Inst():SetModulesSwitch(8, 1)
  1401. local items = {}
  1402. local index = 0
  1403. while true do
  1404. local filename = filepath .. string.format("%02d.png", index)
  1405. if not global.FileUtilCtl:isFileExist(filename) then
  1406. break
  1407. end
  1408. table.insert(items, filename)
  1409. index = index + 1
  1410. end
  1411. --
  1412. local function showSplashAuto()
  1413. if #items <= 0 then
  1414. finishCB()
  1415. return
  1416. end
  1417. local filename = table.remove(items, 1)
  1418. local image = ccui.ImageView:create()
  1419. image:loadTexture( filename )
  1420. image:setPosition( viewSize.width * 0.5, viewSize.height * 0.5 )
  1421. image:setAnchorPoint( 0.5, 0.5 )
  1422. layer:addChild( image, 999 )
  1423. image:setOpacity( 0 )
  1424. image:runAction( cc.Sequence:create(
  1425. cc.FadeIn:create( SplashFadeInTime ),
  1426. cc.DelayTime:create( SplashTime ),
  1427. cc.FadeTo:create( SplashFadeOutTime, 20 ),
  1428. cc.CallFunc:create(function()
  1429. showSplashAuto()
  1430. end),
  1431. cc.RemoveSelf:create()
  1432. ) )
  1433. -- remove texture cache
  1434. global.TextureCache:removeTextureForKey( filename )
  1435. end
  1436. showSplashAuto()
  1437. end
  1438. startSplash()
  1439. end
  1440. function GameEnvManager:OnGameSuspend()
  1441. release_print("function GameEnvManager:OnGameSuspend()")
  1442. self._isGameSuspend = true
  1443. end
  1444. function GameEnvManager:OnGameResumed()
  1445. release_print("function GameEnvManager:OnGameResumed()")
  1446. self._isGameSuspend = false
  1447. -- 所有暂停期间的回调处理
  1448. for i, v in ipairs(self._suspendCBCache) do
  1449. v()
  1450. end
  1451. self._suspendCBCache = {}
  1452. end
  1453. function GameEnvManager:OnSizeChanged(width, height)
  1454. local frameFactor = width / height
  1455. local designPolicy = cc.ResolutionPolicy.FIXED_HEIGHT
  1456. if frameFactor > 1.8 then -- 17:9 = 1.889
  1457. designPolicy = cc.ResolutionPolicy.FIXED_HEIGHT
  1458. else -- 16:9 = 1.778
  1459. designPolicy = cc.ResolutionPolicy.FIXED_WIDTH
  1460. end
  1461. local glview = cc.Director:getInstance():getOpenGLView()
  1462. glview:setFrameSize(width, height)
  1463. local width = global.DesignSize_Win.width
  1464. local height = global.DesignSize_Win.height
  1465. if global.isWindows and width > global.DeviceWith_Win or height > global.DeviceHeight_Win then
  1466. width = global.DeviceWith_Win
  1467. height = global.DeviceHeight_Win
  1468. end
  1469. glview:setDesignResolutionSize(width, height, designPolicy)
  1470. self:RestartGame()
  1471. end
  1472. function GameEnvManager:OnScreenSizeChanged(width, height)
  1473. if self._framesizeOriWidth == width and self._framesizeOriHeight == height then
  1474. return
  1475. end
  1476. if self._framesizeOriWidth == height and self._framesizeOriHeight == width then
  1477. return
  1478. end
  1479. self:OnSizeChanged(width, height)
  1480. end
  1481. -------------------------------------------------------------
  1482. function GameEnvManager:launch()
  1483. local glview = cc.Director:getInstance():getOpenGLView()
  1484. local framesize = glview:getFrameSize()
  1485. self._framesizeOriWidth = framesize.width
  1486. self._framesizeOriHeight = framesize.height
  1487. -- stateMgr, for pause & resume
  1488. gameStateMgr:Inst():RegisterLuaHandler( function( appState, p1, p2)
  1489. if 0 == appState then
  1490. self:OnGameSuspend()
  1491. elseif 1 == appState then
  1492. self:OnGameResumed()
  1493. elseif 2 == appState then
  1494. self:OnScreenSizeChanged(p1, p2)
  1495. end
  1496. end )
  1497. local function loadGame()
  1498. -- load game env
  1499. global.L_GameEnvManager:LoadGameEnv()
  1500. global.L_DataRePort:Init()
  1501. --------------------------------------------
  1502. local glview = cc.Director:getInstance():getOpenGLView()
  1503. local frameSize = cc.Director:getInstance():getOpenGLView():getFrameSize()
  1504. if frameSize.width < frameSize.height then --竖屏
  1505. global.IS_PORTRAIT = true
  1506. local w = global.DesignSize_Oth.width
  1507. global.DesignSize_Oth.width = global.DesignSize_Oth.height
  1508. global.DesignSize_Oth.height = w
  1509. end
  1510. local frameFactor = frameSize.width / frameSize.height
  1511. local designPolicy = cc.ResolutionPolicy.FIXED_HEIGHT
  1512. if frameFactor > 1.8 then -- 17:9 = 1.889
  1513. designPolicy = cc.ResolutionPolicy.FIXED_HEIGHT
  1514. else -- 16:9 = 1.778
  1515. designPolicy = cc.ResolutionPolicy.FIXED_WIDTH
  1516. end
  1517. if cc.PLATFORM_OS_WINDOWS == cc.Application:getInstance():getTargetPlatform() then
  1518. -- 自适应屏幕
  1519. local monitorWidth = 0
  1520. local monitorHeight = 0
  1521. if getWindowWidth and getWindowHeight then
  1522. monitorWidth = getWindowWidth()
  1523. monitorHeight = getWindowHeight()
  1524. end
  1525. if monitorWidth ~= 0 and monitorHeight ~= 0 then
  1526. global.DeviceSize_Win.width = math.min(global.DeviceSize_Win.width, (monitorWidth-20))
  1527. global.DeviceSize_Win.height = math.min(global.DeviceSize_Win.height, (monitorHeight-100))
  1528. if monitorWidth > 1920 or monitorHeight > 1080 then
  1529. global.WINIS4K = true
  1530. end
  1531. end
  1532. release_print(global.DeviceSize_Win.width, global.DeviceSize_Win.height)
  1533. glview:setFrameSize(global.DeviceSize_Win.width, global.DeviceSize_Win.height)
  1534. local width = global.DesignSize_Win.width
  1535. local height = global.DesignSize_Win.height
  1536. if width > global.DeviceWith_Win or height > global.DeviceHeight_Win then
  1537. width = global.DeviceWith_Win
  1538. height = global.DeviceHeight_Win
  1539. end
  1540. glview:setDesignResolutionSize(width, height, designPolicy)
  1541. -- glview:setFrameZoomFactor( global.DeviceZoom_Win )
  1542. else
  1543. glview:setDesignResolutionSize(global.DesignSize_Oth.width, global.DesignSize_Oth.height, designPolicy)
  1544. end
  1545. --------------------------------------------
  1546. ----------ttfScale-----
  1547. --c++版本大于等于1
  1548. if LuaBridgeCtl:Inst():GetModulesSwitch(global.Modules_Index_Cpp_Version) >= global.CPP_VERSION_LABEL_TTF then
  1549. if cc.PLATFORM_OS_WINDOWS ~= cc.Application:getInstance():getTargetPlatform() then
  1550. local frameSize = glview:getFrameSize()
  1551. local DesignSize = glview:getDesignResolutionSize()
  1552. local ttfscale = 1
  1553. if designPolicy == cc.ResolutionPolicy.FIXED_HEIGHT then
  1554. ttfscale = frameSize.height / DesignSize.height
  1555. elseif designPolicy == cc.ResolutionPolicy.FIXED_WIDTH then
  1556. ttfscale = frameSize.width / DesignSize.width
  1557. end
  1558. if cc.Label.setTTFAliasTexParameters then
  1559. cc.Label:setTTFAliasTexParameters(true)
  1560. end
  1561. if cc.Label.setTTFScaleFactor then
  1562. cc.Label:setTTFScaleFactor(ttfscale)
  1563. end
  1564. end
  1565. end
  1566. --------------------------------------------
  1567. -- 游戏名
  1568. local viewName = global.L_GameEnvManager:GetEnvDataByKey("viewName")
  1569. if cc.PLATFORM_OS_WINDOWS == cc.Application:getInstance():getTargetPlatform() then
  1570. glview:setViewName(viewName or "")
  1571. end
  1572. -- init game layer
  1573. global.L_GameLayerManager:Init()
  1574. -- init system tips
  1575. global.L_SystemTipsManager:OpenLayer()
  1576. -- open module choose layer
  1577. global.L_ModuleChooseManager:OpenLayer()
  1578. -- native notice
  1579. global.L_NativeBridgeManager:GN_LaunchGame()
  1580. -- load game info && request mod info list
  1581. global.L_GameEnvManager:StartGame()
  1582. end
  1583. -------------------------------------------------
  1584. -- 是否能进入,需要权限且拥有权限
  1585. local function checkPermission()
  1586. if global.isWindows then
  1587. return true
  1588. end
  1589. if global.L_NativeBridgeManager._revcData and not self:isNeedPermission() then
  1590. return true
  1591. end
  1592. if self:isNeedPermission() and self:isHasPermission() then
  1593. return true
  1594. end
  1595. return false
  1596. end
  1597. -- 尝试进入游戏
  1598. local function checkLoad()
  1599. if checkPermission() then
  1600. loadGame()
  1601. return
  1602. end
  1603. self._launchScheduleID = Schedule(function()
  1604. if checkPermission() then
  1605. loadGame()
  1606. -- 停止定时器
  1607. if self._launchScheduleID then
  1608. UnSchedule(self._launchScheduleID)
  1609. self._launchScheduleID = nil
  1610. end
  1611. else
  1612. local jData = {}
  1613. jData.needUDID = 1
  1614. global.L_NativeBridgeManager:GN_appLaunchNotify(jData)
  1615. end
  1616. end, 1/60)
  1617. end
  1618. checkLoad()
  1619. if global.L_GameEnvManager:GetEnvDataByKey("pc_close_secoend_tips") == 1 then
  1620. global.L_NativeBridgeManager:GN_IsCan_Windown_Close_State({state=0})
  1621. end
  1622. end
  1623. return GameEnvManager