GPGSUpgrader.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. // <copyright file="GPGSUpgrader.cs" company="Google Inc.">
  2. // Copyright (C) 2014 Google Inc.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. // </copyright>
  16. #if (UNITY_ANDROID || (UNITY_IPHONE && !NO_GPGS))
  17. namespace GooglePlayGames.Editor
  18. {
  19. using System.IO;
  20. using UnityEditor;
  21. using UnityEngine;
  22. /// <summary>
  23. /// GPGS upgrader handles performing and upgrade tasks.
  24. /// </summary>
  25. [InitializeOnLoad]
  26. public class GPGSUpgrader
  27. {
  28. /// <summary>
  29. /// Initializes static members of the <see cref="GooglePlayGames.GPGSUpgrader"/> class.
  30. /// </summary>
  31. static GPGSUpgrader()
  32. {
  33. string prevVer = GPGSProjectSettings.Instance.Get(GPGSUtil.LASTUPGRADEKEY, "00000");
  34. if (!prevVer.Equals(PluginVersion.VersionKey))
  35. {
  36. // if this is a really old version, upgrade to 911 first, then 915
  37. if (!prevVer.Equals(PluginVersion.VersionKeyCPP))
  38. {
  39. prevVer = Upgrade911(prevVer);
  40. }
  41. prevVer = Upgrade915(prevVer);
  42. prevVer = Upgrade927Patch(prevVer);
  43. // Upgrade to remove gpg version of jar resolver
  44. prevVer = Upgrade928(prevVer);
  45. prevVer = Upgrade930(prevVer);
  46. prevVer = Upgrade931(prevVer);
  47. prevVer = Upgrade935(prevVer);
  48. prevVer = Upgrade941(prevVer);
  49. prevVer = Upgrade942 (prevVer);
  50. // there is no migration needed to 930+
  51. if (!prevVer.Equals(PluginVersion.VersionKey))
  52. {
  53. Debug.Log("Upgrading from format version " + prevVer + " to " + PluginVersion.VersionKey);
  54. prevVer = PluginVersion.VersionKey;
  55. }
  56. string msg = GPGSStrings.PostInstall.Text.Replace(
  57. "$VERSION",
  58. PluginVersion.VersionString);
  59. EditorUtility.DisplayDialog(GPGSStrings.PostInstall.Title, msg, "OK");
  60. }
  61. GPGSProjectSettings.Instance.Set(GPGSUtil.LASTUPGRADEKEY, prevVer);
  62. GPGSProjectSettings.Instance.Set(GPGSUtil.PLUGINVERSIONKEY,
  63. PluginVersion.VersionString);
  64. GPGSProjectSettings.Instance.Save();
  65. // clean up duplicate scripts if Unity 5+
  66. int ver = GPGSUtil.GetUnityMajorVersion();
  67. if (ver >= 5)
  68. {
  69. string[] paths =
  70. {
  71. "Assets/GooglePlayGames",
  72. "Assets/Plugins/Android",
  73. "Assets/PlayServicesResolver"
  74. };
  75. foreach (string p in paths)
  76. {
  77. CleanDuplicates(p);
  78. }
  79. // remove support lib from old location.
  80. string jarFile =
  81. "Assets/Plugins/Android/libs/android-support-v4.jar";
  82. if (File.Exists(jarFile))
  83. {
  84. File.Delete(jarFile);
  85. }
  86. // remove the massive play services client lib
  87. string clientDir = "Assets/Plugins/Android/google-play-services_lib";
  88. GPGSUtil.DeleteDirIfExists(clientDir);
  89. }
  90. // Check that there is a AndroidManifest.xml file
  91. if (!GPGSUtil.AndroidManifestExists())
  92. {
  93. GPGSUtil.GenerateAndroidManifest();
  94. }
  95. AssetDatabase.Refresh();
  96. }
  97. /// <summary>
  98. /// Cleans the duplicate files. There should not be any since
  99. /// we are keeping track of the .meta files.
  100. /// </summary>
  101. /// <param name="root">Root of the directory to clean.</param>
  102. private static void CleanDuplicates(string root)
  103. {
  104. string[] subDirs = Directory.GetDirectories(root);
  105. // look for .1 and .2
  106. string[] dups = Directory.GetFiles(root, "* 1.*");
  107. foreach (string d in dups)
  108. {
  109. Debug.Log("Deleting duplicate file: " + d);
  110. File.Delete(d);
  111. }
  112. dups = Directory.GetFiles(root, "* 2.*");
  113. foreach (string d in dups)
  114. {
  115. Debug.Log("Deleting duplicate file: " + d);
  116. File.Delete(d);
  117. }
  118. // recurse
  119. foreach (string s in subDirs)
  120. {
  121. CleanDuplicates(s);
  122. }
  123. }
  124. private static string Upgrade942(string prevVer)
  125. {
  126. string file = "Assets/Plugins/Android/play-games-plugin-support.aar";
  127. if (File.Exists(file))
  128. {
  129. Debug.Log("Deleting obsolete file: " + file);
  130. File.Delete(file);
  131. }
  132. return PluginVersion.VersionKey;
  133. }
  134. /// <summary> Upgrade to 0.9.41 </summary>
  135. /// <remarks>This cleans up the Plugins/Android directory since
  136. /// the libraries where refactored into the .aar file. This
  137. /// also renames MainLibProj to GooglePlayGamesManifest.
  138. /// </remarks>
  139. private static string Upgrade941 (string prevVer)
  140. {
  141. string[] obsoleteDirectories = {
  142. "Assets/Plugins/Android/MainLibProj",
  143. };
  144. string[] obsoleteFiles = {
  145. "Assets/GooglePlayGames/Editor/GPGSDependencies.cs",
  146. "Assets/GooglePlayGames/Editor/GPGSDependencies.cs.meta"
  147. };
  148. foreach (string directory in obsoleteDirectories) {
  149. if (Directory.Exists (directory)) {
  150. Debug.Log ("Deleting obsolete directory: " + directory);
  151. Directory.Delete (directory, true);
  152. }
  153. }
  154. foreach (string file in obsoleteFiles)
  155. {
  156. if (File.Exists(file))
  157. {
  158. Debug.Log("Deleting obsolete file: " + file);
  159. File.Delete(file);
  160. }
  161. }
  162. return PluginVersion.VersionKey;
  163. }
  164. /// <summary>
  165. /// Upgrade to 0.9.35
  166. /// </summary>
  167. /// <remarks>
  168. /// This cleans up some unused files mostly related to the improved jar resolver.
  169. /// </remarks>
  170. /// <param name="prevVer">Previous ver.</param>
  171. private static string Upgrade935(string prevVer)
  172. {
  173. string[] obsoleteFiles =
  174. {
  175. "Assets/GooglePlayGames/Editor/CocoaPodHelper.cs",
  176. "Assets/GooglePlayGames/Editor/CocoaPodHelper.cs.meta",
  177. "Assets/GooglePlayGames/Editor/GPGSInstructionWindow.cs",
  178. "Assets/GooglePlayGames/Editor/GPGSInstructionWindow.cs.meta",
  179. "Assets/GooglePlayGames/Editor/Podfile.txt",
  180. "Assets/GooglePlayGames/Editor/Podfile.txt.meta",
  181. "Assets/GooglePlayGames/Editor/cocoapod_instructions",
  182. "Assets/GooglePlayGames/Editor/cocoapod_instructions.meta",
  183. "Assets/GooglePlayGames/Editor/ios_instructions",
  184. "Assets/GooglePlayGames/Editor/ios_instructions.meta",
  185. "Assets/PlayServicesResolver/Editor/DefaultResolver.cs",
  186. "Assets/PlayServicesResolver/Editor/DefaultResolver.cs.meta",
  187. "Assets/PlayServicesResolver/Editor/IResolver.cs",
  188. "Assets/PlayServicesResolver/Editor/IResolver.cs.meta",
  189. "Assets/PlayServicesResolver/Editor/JarResolverLib.dll",
  190. "Assets/PlayServicesResolver/Editor/JarResolverLib.dll.meta",
  191. "Assets/PlayServicesResolver/Editor/PlayServicesResolver.cs",
  192. "Assets/PlayServicesResolver/Editor/PlayServicesResolver.cs.meta",
  193. "Assets/PlayServicesResolver/Editor/ResolverVer1_1.cs",
  194. "Assets/PlayServicesResolver/Editor/ResolverVer1_1.cs.meta",
  195. "Assets/PlayServicesResolver/Editor/SampleDependencies.cs",
  196. "Assets/PlayServicesResolver/Editor/SampleDependencies.cs.meta",
  197. "Assets/PlayServicesResolver/Editor/SettingsDialog.cs",
  198. "Assets/PlayServicesResolver/Editor/SettingsDialog.cs.meta",
  199. "Assets/Plugins/Android/play-services-plus-8.4.0.aar",
  200. "Assets/PlayServicesResolver/Editor/play-services-plus-8.4.0.aar.meta",
  201. // not an obsolete file, but delete the cache since the schema changed.
  202. "ProjectSettings/GoogleDependencyGooglePlayGames.xml"
  203. };
  204. foreach (string file in obsoleteFiles)
  205. {
  206. if (File.Exists(file))
  207. {
  208. Debug.Log("Deleting obsolete file: " + file);
  209. File.Delete(file);
  210. }
  211. }
  212. return PluginVersion.VersionKey;
  213. }
  214. /// <summary>
  215. /// Upgrade to 0.9.31
  216. /// </summary>
  217. /// <remarks>
  218. /// This cleans up some unused files.
  219. /// </remarks>
  220. /// <param name="prevVer">Previous ver.</param>
  221. private static string Upgrade931(string prevVer)
  222. {
  223. string[] obsoleteFiles =
  224. {
  225. "Assets/GooglePlayGames/Editor/GPGSExportPackageUI.cs",
  226. "Assets/GooglePlayGames/Editor/GPGSExportPackageUI.cs.meta"
  227. };
  228. foreach (string file in obsoleteFiles)
  229. {
  230. if (File.Exists(file))
  231. {
  232. Debug.Log("Deleting obsolete file: " + file);
  233. File.Delete(file);
  234. }
  235. }
  236. return PluginVersion.VersionKey;
  237. }
  238. /// <summary>
  239. /// Upgrade to 930 from the specified prevVer.
  240. /// </summary>
  241. /// <param name="prevVer">Previous ver.</param>
  242. /// <returns>the version string upgraded to.</returns>
  243. private static string Upgrade930(string prevVer)
  244. {
  245. Debug.Log("Upgrading from format version " + prevVer + " to " + PluginVersion.VersionKeyNativeCRM);
  246. // As of 930, the CRM API is handled by the Native SDK, not GmsCore.
  247. string[] obsoleteFiles =
  248. {
  249. "Assets/GooglePlayGames/Platforms/Android/Gms/Games/Games.cs",
  250. "Assets/GooglePlayGames/Platforms/Android/Gms/Games/Games.cs.meta",
  251. "Assets/GooglePlayGames/Platforms/Android/Gms/Games/Stats/LoadPlayerStatsResultObject.cs",
  252. "Assets/GooglePlayGames/Platforms/Android/Gms/Games/Stats/LoadPlayerStatsResultObject.cs.meta",
  253. "Assets/GooglePlayGames/Platforms/Android/Gms/Games/Stats/PlayerStats.cs",
  254. "Assets/GooglePlayGames/Platforms/Android/Gms/Games/Stats/PlayerStats.cs.meta",
  255. "Assets/GooglePlayGames/Platforms/Android/Gms/Games/Stats/PlayerStatsObject.cs",
  256. "Assets/GooglePlayGames/Platforms/Android/Gms/Games/Stats/PlayerStatsObject.cs.meta",
  257. "Assets/GooglePlayGames/Platforms/Android/Gms/Games/Stats/Stats.cs",
  258. "Assets/GooglePlayGames/Platforms/Android/Gms/Games/Stats/Stats.cs.meta",
  259. "Assets/GooglePlayGames/Platforms/Android/Gms/Games/Stats/StatsObject.cs",
  260. "Assets/GooglePlayGames/Platforms/Android/Gms/Games/Stats/StatsObject.cs.meta"
  261. };
  262. // only delete these if we are not version 0.9.34
  263. if (string.Compare(PluginVersion.VersionKey, PluginVersion.VersionKeyJNIStats,
  264. System.StringComparison.Ordinal) <= 0)
  265. {
  266. foreach (string file in obsoleteFiles)
  267. {
  268. if (File.Exists(file))
  269. {
  270. Debug.Log("Deleting obsolete file: " + file);
  271. File.Delete(file);
  272. }
  273. }
  274. }
  275. return PluginVersion.VersionKeyNativeCRM;
  276. }
  277. private static string Upgrade928(string prevVer)
  278. {
  279. //remove the jar resolver and if found, then
  280. // warn the user that restarting the editor is required.
  281. string[] obsoleteFiles =
  282. {
  283. "Assets/GooglePlayGames/Editor/JarResolverLib.dll",
  284. "Assets/GooglePlayGames/Editor/JarResolverLib.dll.meta",
  285. "Assets/GooglePlayGames/Editor/BackgroundResolution.cs",
  286. "Assets/GooglePlayGames/Editor/BackgroundResolution.cs.meta"
  287. };
  288. bool found = File.Exists(obsoleteFiles[0]);
  289. foreach (string file in obsoleteFiles)
  290. {
  291. if (File.Exists(file))
  292. {
  293. Debug.Log("Deleting obsolete file: " + file);
  294. File.Delete(file);
  295. }
  296. }
  297. if (found)
  298. {
  299. GPGSUtil.Alert("This update made changes that requires that you restart the editor");
  300. }
  301. Debug.Log("Upgrading from version " + prevVer + " to " + PluginVersion.VersionKeyJarResolver);
  302. return PluginVersion.VersionKeyJarResolver;
  303. }
  304. /// <summary>
  305. /// Upgrade to 0.9.27a.
  306. /// </summary>
  307. /// <remarks>This removes the GPGGizmo class, which broke the editor</remarks>
  308. /// <returns>The patched version</returns>
  309. /// <param name="prevVer">Previous version</param>
  310. private static string Upgrade927Patch(string prevVer)
  311. {
  312. string[] obsoleteFiles =
  313. {
  314. "Assets/GooglePlayGames/Editor/GPGGizmo.cs",
  315. "Assets/GooglePlayGames/Editor/GPGGizmo.cs.meta",
  316. "Assets/GooglePlayGames/BasicApi/OnStateLoadedListener.cs",
  317. "Assets/GooglePlayGames/BasicApi/OnStateLoadedListener.cs.meta",
  318. "Assets/GooglePlayGames/Platforms/Native/AndroidAppStateClient.cs",
  319. "Assets/GooglePlayGames/Platforms/Native/AndroidAppStateClient.cs.meta",
  320. "Assets/GooglePlayGames/Platforms/Native/UnsupportedAppStateClient.cs",
  321. "Assets/GooglePlayGames/Platforms/Native/UnsupportedAppStateClient.cs.meta"
  322. };
  323. foreach (string file in obsoleteFiles)
  324. {
  325. if (File.Exists(file))
  326. {
  327. Debug.Log("Deleting obsolete file: " + file);
  328. File.Delete(file);
  329. }
  330. }
  331. return PluginVersion.VersionKey27Patch;
  332. }
  333. /// <summary>
  334. /// Upgrade to 915 from the specified prevVer.
  335. /// </summary>
  336. /// <param name="prevVer">Previous ver.</param>
  337. /// <returns>the version string upgraded to.</returns>
  338. private static string Upgrade915(string prevVer)
  339. {
  340. Debug.Log("Upgrading from format version " + prevVer + " to " + PluginVersion.VersionKeyU5);
  341. // all that was done was moving the Editor files to be in GooglePlayGames/Editor
  342. string[] obsoleteFiles =
  343. {
  344. "Assets/Editor/GPGSAndroidSetupUI.cs",
  345. "Assets/Editor/GPGSAndroidSetupUI.cs.meta",
  346. "Assets/Editor/GPGSDocsUI.cs",
  347. "Assets/Editor/GPGSDocsUI.cs.meta",
  348. "Assets/Editor/GPGSIOSSetupUI.cs",
  349. "Assets/Editor/GPGSIOSSetupUI.cs.meta",
  350. "Assets/Editor/GPGSInstructionWindow.cs",
  351. "Assets/Editor/GPGSInstructionWindow.cs.meta",
  352. "Assets/Editor/GPGSPostBuild.cs",
  353. "Assets/Editor/GPGSPostBuild.cs.meta",
  354. "Assets/Editor/GPGSProjectSettings.cs",
  355. "Assets/Editor/GPGSProjectSettings.cs.meta",
  356. "Assets/Editor/GPGSStrings.cs",
  357. "Assets/Editor/GPGSStrings.cs.meta",
  358. "Assets/Editor/GPGSUpgrader.cs",
  359. "Assets/Editor/GPGSUpgrader.cs.meta",
  360. "Assets/Editor/GPGSUtil.cs",
  361. "Assets/Editor/GPGSUtil.cs.meta",
  362. "Assets/Editor/GameInfo.template",
  363. "Assets/Editor/GameInfo.template.meta",
  364. "Assets/Editor/PlistBuddyHelper.cs",
  365. "Assets/Editor/PlistBuddyHelper.cs.meta",
  366. "Assets/Editor/PostprocessBuildPlayer",
  367. "Assets/Editor/PostprocessBuildPlayer.meta",
  368. "Assets/Editor/ios_instructions",
  369. "Assets/Editor/ios_instructions.meta",
  370. "Assets/Editor/projsettings.txt",
  371. "Assets/Editor/projsettings.txt.meta",
  372. "Assets/Editor/template-AndroidManifest.txt",
  373. "Assets/Editor/template-AndroidManifest.txt.meta",
  374. "Assets/Plugins/Android/libs/armeabi/libgpg.so",
  375. "Assets/Plugins/Android/libs/armeabi/libgpg.so.meta",
  376. "Assets/Plugins/iOS/GPGSAppController 1.h",
  377. "Assets/Plugins/iOS/GPGSAppController 1.h.meta",
  378. "Assets/Plugins/iOS/GPGSAppController 1.mm",
  379. "Assets/Plugins/iOS/GPGSAppController 1.mm.meta"
  380. };
  381. foreach (string file in obsoleteFiles)
  382. {
  383. if (File.Exists(file))
  384. {
  385. Debug.Log("Deleting obsolete file: " + file);
  386. File.Delete(file);
  387. }
  388. }
  389. return PluginVersion.VersionKeyU5;
  390. }
  391. /// <summary>
  392. /// Upgrade to 911 from the specified prevVer.
  393. /// </summary>
  394. /// <param name="prevVer">Previous ver.</param>
  395. /// <returns>the version string upgraded to.</returns>
  396. private static string Upgrade911(string prevVer)
  397. {
  398. Debug.Log("Upgrading from format version " + prevVer + " to " + PluginVersion.VersionKeyCPP);
  399. // delete obsolete files, if they are there
  400. string[] obsoleteFiles =
  401. {
  402. "Assets/GooglePlayGames/OurUtils/Utils.cs",
  403. "Assets/GooglePlayGames/OurUtils/Utils.cs.meta",
  404. "Assets/GooglePlayGames/OurUtils/MyClass.cs",
  405. "Assets/GooglePlayGames/OurUtils/MyClass.cs.meta",
  406. "Assets/Plugins/GPGSUtils.dll",
  407. "Assets/Plugins/GPGSUtils.dll.meta",
  408. };
  409. foreach (string file in obsoleteFiles)
  410. {
  411. if (File.Exists(file))
  412. {
  413. Debug.Log("Deleting obsolete file: " + file);
  414. File.Delete(file);
  415. }
  416. }
  417. // delete obsolete directories, if they are there
  418. string[] obsoleteDirectories =
  419. {
  420. "Assets/Plugins/Android/BaseGameUtils"
  421. };
  422. foreach (string directory in obsoleteDirectories)
  423. {
  424. if (Directory.Exists(directory))
  425. {
  426. Debug.Log("Deleting obsolete directory: " + directory);
  427. Directory.Delete(directory, true);
  428. }
  429. }
  430. Debug.Log("Done upgrading from format version " + prevVer + " to " + PluginVersion.VersionKeyCPP);
  431. return PluginVersion.VersionKeyCPP;
  432. }
  433. }
  434. }
  435. #endif