Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ApkExpansionSupport.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under Apache 2.0 License. See LICENSE.md for details.
3 //
4 // --------------------------------------------------------------------------------------------------------------------
5 // <copyright file="ApkExpansionSupport.cs" company="Matthew Leibowitz">
6 // Copyright (c) Matthew Leibowitz
7 // This code is licensed under the Apache 2.0 License
8 // http://www.apache.org/licenses/LICENSE-2.0.html
9 // </copyright>
10 // <summary>
11 // The apk expansion support.
12 // </summary>
13 // --------------------------------------------------------------------------------------------------------------------
14 
15 namespace System.IO.Compression.Zip
16 {
17  using System.Collections.Generic;
18 
19  using Android.Content;
20  using Android.OS;
21 
22  /// <summary>
23  /// The apk expansion support.
24  /// </summary>
25  public static class ApkExpansionSupport
26  {
27  #region Constants
28 
29  /// <summary>
30  /// The shared path to all app expansion files
31  /// </summary>
32  private const string ExpansionFilesPath = "/Android/obb/";
33 
34  #endregion
35 
36  #region Public Methods and Operators
37 
38  /// <summary>
39  /// The get apk expansion files.
40  /// </summary>
41  /// <param name="ctx">
42  /// The ctx.
43  /// </param>
44  /// <param name="mainVersion">
45  /// The main version.
46  /// </param>
47  /// <param name="patchVersion">
48  /// The patch version.
49  /// </param>
50  /// <returns>
51  /// A list of obb files for this app.
52  /// </returns>
53  public static IEnumerable<string> GetApkExpansionFiles(Context ctx, int mainVersion, int patchVersion)
54  {
55  var ret = new List<string>();
56 
57  if (Environment.ExternalStorageState.Equals(Environment.MediaMounted))
58  {
59  string packageName = ctx.PackageName;
60 
61  // Build the full path to the app's expansion files
62  string expPath = Environment.ExternalStorageDirectory + ExpansionFilesPath + packageName;
63 
64  // Check that expansion file path exists
65  if (Directory.Exists(expPath))
66  {
67  string main = Path.Combine(expPath, string.Format("main.{0}.{1}.obb", mainVersion, packageName));
68  string patch = Path.Combine(expPath, string.Format("patch.{0}.{1}.obb", mainVersion, packageName));
69 
70  if (mainVersion > 0 && File.Exists(main))
71  {
72  ret.Add(main);
73  }
74 
75  if (patchVersion > 0 && File.Exists(patch))
76  {
77  ret.Add(patch);
78  }
79  }
80  }
81 
82  return ret.ToArray();
83  }
84 
85  /// <summary>
86  /// Gets a <see cref="ExpansionZipFile"/> that contains a list of all
87  /// the files in the combined main and patch obb packages.
88  /// </summary>
89  /// <param name="ctx">
90  /// The context.
91  /// </param>
92  /// <param name="mainVersion">
93  /// The main obb version.
94  /// </param>
95  /// <param name="patchVersion">
96  /// The patch obb version.
97  /// </param>
98  /// <returns>
99  /// The apk expansion zip file.
100  /// </returns>
101  public static ExpansionZipFile GetApkExpansionZipFile(Context ctx, int mainVersion, int patchVersion)
102  {
103  return new ExpansionZipFile(GetApkExpansionFiles(ctx, mainVersion, patchVersion));
104  }
105 
106  #endregion
107  }
108 }
static ExpansionZipFile GetApkExpansionZipFile(Context ctx, int mainVersion, int patchVersion)
Gets a ExpansionZipFile that contains a list of all the files in the combined main and patch obb pack...
static IEnumerable< string > GetApkExpansionFiles(Context ctx, int mainVersion, int patchVersion)
The get apk expansion files.
System.IO.File File
Compression
Compression method enumeration
Definition: Compression.cs:20