11/*
2- * Copyright (c) 2024 PlayEveryWare
3- *
4- * Permission is hereby granted, free of charge, to any person obtaining a copy
5- * of this software and associated documentation files (the "Software"), to deal
6- * in the Software without restriction, including without limitation the rights
7- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8- * copies of the Software, and to permit persons to whom the Software is
9- * furnished to do so, subject to the following conditions:
10- *
11- * The above copyright notice and this permission notice shall be included in all
12- * copies or substantial portions of the Software.
13- *
14- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20- * SOFTWARE.
21- */
2+ * Copyright (c) 2024 PlayEveryWare
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5+ * of this software and associated documentation files (the "Software"), to deal
6+ * in the Software without restriction, including without limitation the rights
7+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+ * copies of the Software, and to permit persons to whom the Software is
9+ * furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice shall be included in all
12+ * copies or substantial portions of the Software.
13+ *
14+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+ * SOFTWARE.
21+ */
2222
2323namespace PlayEveryWare . EpicOnlineServices
2424{
2525 using System ;
26+ using System . IO ;
2627 using System . Threading . Tasks ;
2728 using UnityEngine ;
2829 using UnityEngine . Networking ;
2930
3031 public class AndroidFileIOHelper
3132 {
32- public static async Task < string > ReadAllText ( string filePath )
33+ public static bool FileExists ( string filePath )
3334 {
3435 using UnityWebRequest request = UnityWebRequest . Get ( filePath ) ;
35- request . timeout = 2 ; //seconds till timeout
36- UnityWebRequestAsyncOperation operation = request . SendWebRequest ( ) ;
36+ request . timeout = 2 ;
37+ request . SendWebRequest ( ) ;
38+ while ( ! request . isDone ) { }
39+
40+ bool exists = ( request . result == UnityWebRequest . Result . Success ) ;
3741
38- while ( ! operation . isDone )
42+ if ( ! exists )
3943 {
40- await Task . Yield ( ) ;
44+ Debug . LogError ( $ "AndroidFileIOHelper says that \" { filePath } \" does not exist." ) ;
4145 }
4246
47+ return exists ;
48+ }
49+
50+ public static string ReadAllText ( string filePath )
51+ {
52+ using UnityWebRequest request = UnityWebRequest . Get ( filePath ) ;
53+ request . timeout = 2 ; //seconds till timeout
54+ request . SendWebRequest ( ) ;
55+
56+ while ( ! request . isDone ) { }
57+
58+ return ProcessRequest ( filePath , request ) ;
59+ }
60+
61+ private static string ProcessRequest ( string filePath , UnityWebRequest request )
62+ {
4363 string text = null ;
4464
4565 switch ( request . result )
@@ -72,4 +92,4 @@ public static async Task<string> ReadAllText(string filePath)
7292 return text ;
7393 }
7494 }
75- }
95+ }
0 commit comments