-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainActivity.cs
115 lines (86 loc) · 3.85 KB
/
MainActivity.cs
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Collections.Generic;
using System.IO;
using Android.App;
using Android.Content.PM;
using Android.Views;
using Android.OS;
using Microsoft.Xna.Framework;
using MineLib.Android.WrapperInstances;
using MineLib.Core.Wrappers;
using MineLib.PGL;
using PCLStorage;
namespace MineLib.Android
{
[Activity(Label = "MineLib.Andoid", MainLauncher = true, Icon = "@drawable/icon", AlwaysRetainTaskState = true, LaunchMode = LaunchMode.SingleInstance,
ScreenOrientation = ScreenOrientation.SensorLandscape, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden)]
public sealed class MainActivity : AndroidGameActivity
{
Action OnBackButtonPressed;
public MainActivity()
{
AppDomainWrapper.Instance = new AppDomainWrapperInstance();
FileSystemWrapper.Instance = new FileSystemWrapperInstance();
NetworkTCPWrapper.Instance = new NetworkTCPWrapperInstance();
ThreadWrapper.Instance = new ThreadWrapperInstance();
var assetsContent = ParseAssetsFolder(Application.Context.Assets.List("Content"), "Content");
MoveContentToExternalStorage(assetsContent);
}
private static void MoveContentToExternalStorage(IEnumerable<string> files)
{
foreach (var file in files)
using (var stream = Application.Context.Assets.Open(Path.Combine("Content", file)))
{
var currentFolder = FileSystemWrapper.ContentFolder;
var directories = file.Split(Path.DirectorySeparatorChar);
if (directories.Length > 1)
for (int i = 0; i < directories.Length - 1; i++)
currentFolder = currentFolder.CreateFolderAsync(directories[i], CreationCollisionOption.OpenIfExists).Result;
var createdFile = currentFolder.CreateFileAsync(Path.GetFileName(file), CreationCollisionOption.ReplaceExisting).Result;
using (var createdFileStream = createdFile.OpenAsync(PCLStorage.FileAccess.ReadAndWrite).Result)
stream.CopyTo(createdFileStream);
}
}
private static IEnumerable<string> ParseAssetsFolder(IEnumerable<string> entries, string path)
{
var returnFiles = new List<string>();
foreach (var entry in entries)
{
if (Path.HasExtension(entry))
returnFiles.Add(entry);
if (!Path.HasExtension(entry))
foreach (var file in ParseAssetsFolder(Application.Context.Assets.List(Path.Combine(path, entry)), Path.Combine(path, entry)))
returnFiles.Add(Path.Combine(entry, file));
}
return returnFiles;
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var t = this.ObbDir;
var game = new Client(PlatformCode, true);
InputWrapper.Instance = new InputWrapperInstance(this, (View)game.Services.GetService(typeof(View)), ref OnBackButtonPressed);
SetContentView((View)game.Services.GetService(typeof(View)));
game.Run();
}
protected override void OnPause()
{
base.OnPause();
}
protected override void OnPostResume()
{
base.OnPostResume();
}
public override void OnBackPressed()
{
base.OnBackPressed();
if(OnBackButtonPressed != null)
OnBackButtonPressed();
}
private static void PlatformCode(Game game) { }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
}
}