InvalidDataChecker.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using UnityEditor;
  2. using UnityEngine;
  3. using System;
  4. using System.Collections;
  5. using UnityEngine.Networking;
  6. namespace AmplifyShaderEditor
  7. {
  8. [InitializeOnLoad]
  9. public class InvalidDataChecker
  10. {
  11. private static string[] m_invalidData = { "674ea7bed6b1cd94b8057074298096db", //"/Samples",
  12. "2738539936eacef409be91f148b2a4a0", //"/Resources",
  13. "c880e50f07f2be9499d414ac6f9f3a7a", //"/Templates",
  14. "563f992b9989cf547ac59bf748442c17"};//"/Textures"};
  15. //private static string m_ASEFolderPath;
  16. private static string m_invalidDataCollected = string.Empty;
  17. static InvalidDataChecker()
  18. {
  19. bool foundInvalidData = false;
  20. //m_ASEFolderPath = AssetDatabase.GUIDToAssetPath( IOUtils.ASEFolderGUID );
  21. int count = 0;
  22. for ( int i = 0; i < m_invalidData.Length; i++ )
  23. {
  24. //m_invalidData[ i ] = m_ASEFolderPath + m_invalidData[ i ];
  25. m_invalidData[ i ] = AssetDatabase.GUIDToAssetPath( m_invalidData[ i ] );
  26. if ( AssetDatabase.IsValidFolder( m_invalidData[ i ] ) )
  27. {
  28. foundInvalidData = true;
  29. m_invalidDataCollected += m_invalidData[ i ]+"\n";
  30. count += 1;
  31. }
  32. }
  33. if ( count < 5 )
  34. {
  35. for ( ; count < 5; count++ )
  36. {
  37. m_invalidDataCollected += "\n";
  38. }
  39. }
  40. if ( foundInvalidData )
  41. {
  42. InvalidDataPopUp window = ( InvalidDataPopUp ) EditorWindow.GetWindow( typeof( InvalidDataPopUp ), true, "Found Invalid Data" );
  43. window.minSize = new Vector2( 502, 265 );
  44. window.maxSize = new Vector2( 502, 265 );
  45. window.Show();
  46. }
  47. EditorApplication.update += Update;
  48. }
  49. static void Update()
  50. {
  51. EditorApplication.update -= Update;
  52. if( !EditorApplication.isPlayingOrWillChangePlaymode )
  53. {
  54. Preferences.ShowOption show = Preferences.ShowOption.Never;
  55. if( !EditorPrefs.HasKey( Preferences.User.Keys.StartUp ) )
  56. {
  57. show = Preferences.ShowOption.Always;
  58. EditorPrefs.SetInt( Preferences.User.Keys.StartUp, 0 );
  59. }
  60. else
  61. {
  62. if( Time.realtimeSinceStartup < 10 )
  63. {
  64. show = (Preferences.ShowOption) EditorPrefs.GetInt( Preferences.User.Keys.StartUp, 0 );
  65. // check version here
  66. if( show == Preferences.ShowOption.OnNewVersion )
  67. {
  68. ASEStartScreen.StartBackgroundTask( StartRequest( ASEStartScreen.ChangelogURL, () =>
  69. {
  70. var changeLog = ChangeLogInfo.CreateFromJSON( www.downloadHandler.text );
  71. if( changeLog != null )
  72. {
  73. if( changeLog.Version > VersionInfo.FullNumber )
  74. ASEStartScreen.Init();
  75. }
  76. } ) );
  77. }
  78. }
  79. }
  80. if( show == Preferences.ShowOption.Always )
  81. ASEStartScreen.Init();
  82. }
  83. }
  84. static UnityWebRequest www;
  85. static IEnumerator StartRequest( string url, Action success = null )
  86. {
  87. using( www = UnityWebRequest.Get( url ) )
  88. {
  89. yield return www.SendWebRequest();
  90. while( www.isDone == false )
  91. yield return null;
  92. if( success != null )
  93. success();
  94. }
  95. }
  96. public static void CleanInvalidData()
  97. {
  98. for ( int i = 0; i < m_invalidData.Length; i++ )
  99. {
  100. if ( FileUtil.DeleteFileOrDirectory( m_invalidData[ i ] ) )
  101. {
  102. Debug.Log( "Removed invalid " + m_invalidData[ i ] );
  103. if ( FileUtil.DeleteFileOrDirectory( m_invalidData[ i ] + ".meta" ) )
  104. {
  105. Debug.Log( "Removed invalid " + m_invalidData[ i ] + ".meta" );
  106. }
  107. }
  108. }
  109. AssetDatabase.Refresh();
  110. }
  111. public static string InvalidDataCollected { get { return m_invalidDataCollected; } }
  112. }
  113. public class InvalidDataPopUp : EditorWindow
  114. {
  115. private readonly GUIContent m_buttonContent = new GUIContent( "Remove Invalid Data" );
  116. private Vector2 m_scrollPosition = Vector2.zero;
  117. public void OnGUI()
  118. {
  119. GUILayout.BeginVertical();
  120. {
  121. GUIStyle labelStyle = new GUIStyle( EditorStyles.label );
  122. labelStyle.alignment = TextAnchor.MiddleCenter;
  123. labelStyle.wordWrap = true;
  124. GUILayout.Label( "\nAmplify Shader Editor " + VersionInfo.StaticToString(), labelStyle, GUILayout.ExpandWidth( true ) );
  125. GUILayout.Space( 5 );
  126. GUILayout.Label( "Invalid/Legacy Data was found on your previous ASE folder which needs to be removed in order for it to work correctly." , labelStyle, GUILayout.ExpandWidth( true ) );
  127. GUILayout.Space( 5 );
  128. GUILayout.Label( "Below are the detected files/folders which require to be removed.", labelStyle, GUILayout.ExpandWidth( true ) );
  129. GUILayout.Space( 5 );
  130. m_scrollPosition = GUILayout.BeginScrollView( m_scrollPosition ,GUILayout.Height(85));
  131. GUILayout.TextArea( InvalidDataChecker.InvalidDataCollected );
  132. GUILayout.EndScrollView();
  133. GUILayout.Label( "VERY IMPORTANT: If you have assets of yours inside these folders you need to move them to another location before hitting the button below or they will be PERMANENTLY DELETED", labelStyle, GUILayout.ExpandWidth( true ) );
  134. GUILayout.Space( 5 );
  135. GUILayout.BeginHorizontal();
  136. {
  137. GUILayout.Space( 151 );
  138. if ( GUILayout.Button( m_buttonContent, GUILayout.Width( 200 ) ) )
  139. {
  140. InvalidDataChecker.CleanInvalidData();
  141. Close();
  142. }
  143. }
  144. GUILayout.EndHorizontal();
  145. }
  146. GUILayout.EndVertical();
  147. }
  148. }
  149. }