Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; //andr
using UnityEngine.SceneManagement;
using System.IO; //
using UnityEngine.Video;//streaming
using UnityEngine.Networking;
using static CommunicationEvents;
using static UIconfig;
//Uploading Files from StreamingAsset folder to the Persistent Folder for Android Devices
public static class StreamingAssetLoader
{
//""
public static string file_1_path = "";
public static string file_1 = "scrolls.json";
//Stages
public static string file_2_path = "Stages";
public static string file_2 = "TechDemo A.JSON";
public static string file_3_path = "Stages";
public static string file_3 = "TechDemo B.JSON";
//ValidationSets
public static string file_4_path = "Stages/ValidationSets";
public static string file_4 = "TechDemo A_val.JSON";
public static string file_5_path = "Stages/ValidationSets";
public static string file_5 = "TechDemo B_val.JSON";
//FactStateMachines
public static string file_6_path = "Stages/ValidationSets/FactStateMachines";
public static string file_6 = "TechDemo A_sol.JSON";
public static string file_7_path = "Stages/ValidationSets/FactStateMachines";
public static string file_7 = "TechDemo B_sol.JSON";
public static string file_8_path = "Config";
public static string file_8 = "Network.JSON";
public static string file_9_path = "";
public static string file_9 = "";
public static string file_10_path = "";
public static string file_10 = "";
public static bool checkPDP()
{
string filePath = Application.persistentDataPath + "/Config/Network.json";
if (System.IO.File.Exists(filePath))
{
return true;
}
return false;
}
public static void NetworkJSON_Save()
{
NetworkJSON myObject = new NetworkJSON();
//MyClass myObject = new MyClass();
myObject.newIP = CommunicationEvents.newIP;
myObject.lastIP = CommunicationEvents.lastIP;
myObject.IPslot1 = CommunicationEvents.IPslot1;
myObject.IPslot2 = CommunicationEvents.IPslot2;
myObject.IPslot3 = CommunicationEvents.IPslot3;
myObject.selecIP = CommunicationEvents.selecIP;
myObject.ControlMode = UIconfig.controlMode;
myObject.TouchMode = UIconfig.touchControlMode;
myObject.TAvisibility = UIconfig.TAvisibility;
myObject.autoOSrecognition = CommunicationEvents.autoOSrecognition;
myObject.Opsys = CommunicationEvents.Opsys;
myObject.FrameITUIversion = UIconfig.FrameITUIversion;
myObject.InputManagerVersion = UIconfig.InputManagerVersion;
myObject.colliderScale_all = UIconfig.colliderScale_all;
myObject.cursorSize = UIconfig.cursorSize;
//Data storage
SafeCreateDirectory(Application.persistentDataPath + "/Config");
//string json = JsonUtility.ToJson(date);
string json = JsonUtility.ToJson(myObject);
StreamWriter Writer = new StreamWriter(Application.persistentDataPath + "/Config/Network.json");
Writer.Write(json);
Writer.Flush();
Writer.Close();
}
public static DirectoryInfo SafeCreateDirectory(string path)
{
//Generate if you don't check if the directory exists
if (Directory.Exists(path))
{
return null;
}
return Directory.CreateDirectory(path);
}
public static void ResetPlayerConfig()
{
RereadFiles_PersistentDataPath();
NetworkJSON_Load();
}
public static void ResetDataPath()
RereadFiles_DataPath();
public static void ResetStreamingAsset()
{
RereadFiles_PersistentDataPath();
RereadFiles_DataPath();
NetworkJSON_Load();
//CSform.CheckIPAdr();
}
public static void RereadFiles_PersistentDataPath()
RereadFileUWR(StreamingAssetLoader.file_8_path, StreamingAssetLoader.file_8, 1);
RereadFileUWR(StreamingAssetLoader.file_1_path, StreamingAssetLoader.file_1, 1);
public static void RereadFiles_DataPath()
RereadFileUWR(StreamingAssetLoader.file_2_path, StreamingAssetLoader.file_2, 0);
RereadFileUWR(StreamingAssetLoader.file_3_path, StreamingAssetLoader.file_3, 0);
RereadFileUWR(StreamingAssetLoader.file_4_path, StreamingAssetLoader.file_4, 0);
RereadFileUWR(StreamingAssetLoader.file_5_path, StreamingAssetLoader.file_5, 0);
RereadFileUWR(StreamingAssetLoader.file_6_path, StreamingAssetLoader.file_6, 0);
RereadFileUWR(StreamingAssetLoader.file_7_path, StreamingAssetLoader.file_7, 0);
RereadFileUWR(StreamingAssetLoader.file_9_path, StreamingAssetLoader.file_9, 0);
RereadFileUWR(StreamingAssetLoader.file_10_path, StreamingAssetLoader.file_10, 0);
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
}
public static void NetworkJSON_Load()
{
var reader = new StreamReader(Application.persistentDataPath + "/Config/Network.JSON");
string json = reader.ReadToEnd();
reader.Close();
NetworkJSON myObjs = JsonUtility.FromJson<NetworkJSON>(json);
if (string.IsNullOrEmpty(myObjs.newIP))
{
CommunicationEvents.newIP = "";
}
else
{
CommunicationEvents.newIP = myObjs.newIP;
}
if (string.IsNullOrEmpty(myObjs.lastIP))
{
CommunicationEvents.lastIP = "";
}
else
{
CommunicationEvents.lastIP = myObjs.lastIP;
}
if (string.IsNullOrEmpty(myObjs.IPslot1))
{
CommunicationEvents.IPslot1 = "";
}
else
{
CommunicationEvents.IPslot1 = myObjs.IPslot1;//myObjs.IPslot1;
}
if (string.IsNullOrEmpty(myObjs.IPslot2))
{
CommunicationEvents.IPslot2 = "";//"Empty";
}
else
{
CommunicationEvents.IPslot2 = myObjs.IPslot2;
}
if (string.IsNullOrEmpty(myObjs.IPslot3))
{
CommunicationEvents.IPslot3 = "";
}
else
{
CommunicationEvents.IPslot3 = myObjs.IPslot3;
}
if (string.IsNullOrEmpty(myObjs.selecIP))
{
CommunicationEvents.selecIP = "";
}
else
{
CommunicationEvents.selecIP = myObjs.selecIP;
}
if (false)
{
}
else
{
UIconfig.controlMode = myObjs.ControlMode;
}
if (false)
{
}
else
{
UIconfig.touchControlMode = myObjs.TouchMode;
}
if (false)
{
}
else
{
UIconfig.TAvisibility = myObjs.TAvisibility;
}
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
if (false)
{
}
else
{
CommunicationEvents.autoOSrecognition = myObjs.autoOSrecognition;
}
if (false)
{
}
else
{
CommunicationEvents.Opsys = myObjs.Opsys;
}
if (false)
{
}
else
{
UIconfig.FrameITUIversion = myObjs.FrameITUIversion;
}
if (false)
{
}
else
{
UIconfig.InputManagerVersion = myObjs.InputManagerVersion;
}
if (false)
{
}
else
{
UIconfig.colliderScale_all = myObjs.colliderScale_all;
}
if (false)
{
}
else
{
UIconfig.cursorSize = myObjs.cursorSize;
}
}
public static void RereadFileUWR(string pathfolders, string fileName, int toMainpath)
{
if (fileName == "")
{
return;
}
string destpathf = pathfolders;
string destname = fileName;
string sourcePath = Path.Combine(Application.streamingAssetsPath, pathfolders);
sourcePath = Path.Combine(sourcePath, fileName);
var loadingRequest = UnityWebRequest.Get(sourcePath);
loadingRequest.SendWebRequest();
while (!loadingRequest.isDone)
{
if (loadingRequest.result == UnityWebRequest.Result.ConnectionError || loadingRequest.result == UnityWebRequest.Result.ProtocolError)
{
break;
}
}
if (loadingRequest.result == UnityWebRequest.Result.ConnectionError || loadingRequest.result == UnityWebRequest.Result.ProtocolError)
{
}
else
{
//copies and unpacks file from apk to persistentDataPath where it can be accessed
string destinationPath = "";
if (toMainpath == 0 && CommunicationEvents.Opsys != 1) { destinationPath = Path.Combine(Application.dataPath, destpathf); }
else
{
destinationPath = Path.Combine(Application.persistentDataPath, destpathf);
}
if (Directory.Exists(destinationPath) == false)
{
Directory.CreateDirectory(destinationPath);
}
File.WriteAllBytes(Path.Combine(destinationPath, destname), loadingRequest.downloadHandler.data);
}
//WWW has been replaced with UnityWebRequest.
/*
public static string RereadFileNA(string pathfolders, string fileName, string destpathf, string destname)
{
if (fileName == "")
{
return "noName";
}
// copies and unpacks file from apk to persistentDataPath where it can be accessed
string destinationPath = Path.Combine(Application.persistentDataPath, destpathf);
if (Directory.Exists(destinationPath) == false)
{
Directory.CreateDirectory(destinationPath);
}
destinationPath = Path.Combine(destinationPath, destname);
string sourcePath = Path.Combine(Application.streamingAssetsPath, pathfolders);
sourcePath = Path.Combine(sourcePath, fileName);
#if UNITY_EDITOR
//string sourcePath = Path.Combine(Application.streamingAssetsPath, pathfolders);
//sourcePath = Path.Combine(sourcePath, fileName);
#else
//string sourcePath = "jar:file://" + Application.dataPath + "!/assets/" + fileName;
//UnityEngine.Debug.Log(string.Format("{0}-{1}-{2}-{3}", sourcePath, File.GetLastWriteTimeUtc(sourcePath), File.GetLastWriteTimeUtc(destinationPath)));
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
//if DB does not exist in persistent data folder (folder "Documents" on iOS) or source DB is newer then copy it
//if (!File.Exists(destinationPath) || (File.GetLastWriteTimeUtc(sourcePath) > File.GetLastWriteTimeUtc(destinationPath)))
if (true)
{
if (sourcePath.Contains("://"))
{
// Android
WWW www = new WWW(sourcePath);
while (!www.isDone) {; } // Wait for download to complete - not pretty at all but easy hack for now
if (string.IsNullOrEmpty(www.error))
{
File.WriteAllBytes(destinationPath, www.bytes);
}
else
{
Debug.Log("ERROR: the file DB named " + fileName + " doesn't exist in the StreamingAssets Folder, please copy it there.");
}
}
else
{
// Mac, Windows, Iphone
//validate the existens of the DB in the original folder (folder "streamingAssets")
if (File.Exists(sourcePath))
{
//copy file - alle systems except Android
File.Copy(sourcePath, destinationPath, true);
}
else
{
Debug.Log("ERROR: the file DB named " + fileName + " doesn't exist in the StreamingAssets Folder, please copy it there.");
}
}
}
StreamReader reader = new StreamReader(destinationPath);
var jsonString = reader.ReadToEnd();
reader.Close();
return jsonString;
}
*/
public static void RereadFileUW4(string pathfolders, string fileName, string destpathf, string destname)
{
if (fileName == "")
{
return;
}
string sourcePath = Path.Combine(Application.streamingAssetsPath, pathfolders);
sourcePath = Path.Combine(sourcePath, fileName);
var loadingRequest = UnityWebRequest.Get(sourcePath);
loadingRequest.SendWebRequest();
while (!loadingRequest.isDone)
if (loadingRequest.result == UnityWebRequest.Result.ConnectionError || loadingRequest.result == UnityWebRequest.Result.ProtocolError)
if (loadingRequest.result==UnityWebRequest.Result.ConnectionError || loadingRequest.result==UnityWebRequest.Result.ProtocolError)
//copies and unpacks file from apk to persistentDataPath where it can be accessed
string destinationPath = Path.Combine(Application.persistentDataPath, destpathf);
if (Directory.Exists(destinationPath) == false)
{
Directory.CreateDirectory(destinationPath);
}
File.WriteAllBytes(Path.Combine(destinationPath, destname), loadingRequest.downloadHandler.data);
}
}
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
public class MyClass
{
public int level;
public float timeElapsed;
public string playerName;
}
public static void Score_Save(string Directory_path, string date)
{
MyClass myObject = new MyClass();
myObject.level = 1;
myObject.timeElapsed = 47.5f;
myObject.playerName = "Dr Charles Francis";
//Data storage
SafeCreateDirectory(Application.persistentDataPath + "/" + Directory_path);
//string json = JsonUtility.ToJson(date);
string json = JsonUtility.ToJson(myObject);
StreamWriter Writer = new StreamWriter(Application.persistentDataPath + "/" + Directory_path + "/date.json");
Writer.Write(json);
Writer.Flush();
Writer.Close();
//RereadFileUW("", "scrolls.json", "test3", "test6.json");
//RereadFileUW("Stages", "TechDemo A.JSON", "test3", "test7.json");
/*
RereadFileUWR("", "scrolls.json");
RereadFileUWR("Stages", "TechDemo A.JSON");
RereadFileUWR("Stages", "TechDemo B.JSON");
RereadFileUWR("Stages/ValidationSets", "TechDemo A_val.JSON");
RereadFileUWR("Stages/ValidationSets", "TechDemo B_val.JSON");
RereadFileUWR("Stages/ValidationSets/FactStateMachines", "TechDemo A_val.JSON");
RereadFileUWR("Stages/ValidationSets/FactStateMachines", "TechDemo B_val.JSON");
*/
}
public static string Score_Load(string Directory_path)
{
//Data acquisition
//var reader = new StreamReader(Application.persistentDataPath + "/" + Directory_path + "/date.json");
//var reader = new StreamReader(Application.persistentDataPath + "/scrolls.json");
//var reader = new StreamReader(Application.persistentDataPath + "/1/scrolls.json");
//var reader = new StreamReader(Application.persistentDataPath + "/test3/test7.json");
//var reader = new StreamReader(Application.persistentDataPath + "Stages/factStateMAchines/TechDemo B_val.JSON");
//var reader = new StreamReader(Application.persistentDataPath + "/Stages/TechDemo B.JSON");
var reader = new StreamReader(Application.persistentDataPath + "/Config/Network.JSON");
string json = reader.ReadToEnd();
reader.Close();
//MyClass myObjs = JsonUtility.FromJson<MyClass>(json);
//SampleData mySampleFile = JsonUtility.FromJson<SampleData>(jsonStr);
return json;//Convert for ease of use
//return myObjs.level.ToString();
}
}