Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
StorageToolApp.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 GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.IO;
6 using System.Linq;
7 using System.Text;
8 using SiliconStudio.Core;
9 using SiliconStudio.Core.IO;
10 using SiliconStudio.Core.Storage;
11 
12 namespace SiliconStudio.Paradox.StorageTool
13 {
14  /// <summary>
15  /// Description of an object entry in the bundle.
16  /// </summary>
17  public class ObjectEntry
18  {
19  public string Location { get; set; }
20 
21  public ObjectId Id { get; set; }
22 
23  public long Size { get; set; }
24 
25  public long SizeNotCompressed { get; set; }
26 
27  public override string ToString()
28  {
29  return string.Format("{0}\t{1}\t{2}\t{3}", Location, Id, Size, SizeNotCompressed);
30  }
31  }
32 
33  /// <summary>
34  /// Utility class to manipulate storage and bundles.
35  /// </summary>
36  public class StorageToolApp
37  {
38  /// <summary>
39  /// List the specified bundle to a txt file and opens it.
40  /// </summary>
41  /// <param name="bundlePath">The bundle path.</param>
42  public static void View(string bundlePath)
43  {
44  var entries = GetBundleListing(bundlePath);
45  var dumpFilePath = bundlePath + ".txt";
46 
47  var text = new StringBuilder();
48  foreach (var entry in entries)
49  {
50  text.AppendLine(entry.ToString());
51  }
52  File.WriteAllText(dumpFilePath, text.ToString());
53 
54  System.Diagnostics.Process.Start(dumpFilePath);
55  }
56 
57  /// <summary>
58  /// Gets the listing from a bundle.
59  /// </summary>
60  /// <param name="bundlePath">The bundle path.</param>
61  /// <returns>System.Collections.Generic.List&lt;SiliconStudio.Paradox.StorageTool.ObjectEntry&gt;.</returns>
62  private static List<ObjectEntry> GetBundleListing(string bundlePath)
63  {
64  if (bundlePath == null) throw new ArgumentNullException("bundlePath");
65  if (Path.GetExtension(bundlePath) != BundleOdbBackend.BundleExtension) throw new StorageAppException("Invalid bundle file [{0}] not having extension [{1}]".ToFormat(bundlePath, BundleOdbBackend.BundleExtension));
66  if (!File.Exists(bundlePath)) throw new StorageAppException("Bundle file [{0}] not found".ToFormat(bundlePath));
67 
68  BundleDescription bundle;
69  using (var stream = File.OpenRead(bundlePath))
70  {
71  bundle = BundleOdbBackend.ReadBundleDescription(stream);
72  }
73 
74  var objectInfos = bundle.Objects.ToDictionary(x => x.Key, x => x.Value);
75 
76 
77  var entries = new List<ObjectEntry>();
78  foreach (var locationIds in bundle.Assets)
79  {
80  var entry = new ObjectEntry { Location = locationIds.Key, Id = locationIds.Value };
81 
82  BundleOdbBackend.ObjectInfo objectInfo;
83  if (objectInfos.TryGetValue(entry.Id, out objectInfo))
84  {
85 
86  entry.Size = objectInfo.EndOffset - objectInfo.StartOffset;
87  entry.SizeNotCompressed = objectInfo.SizeNotCompressed;
88  }
89  entries.Add(entry);
90  }
91 
92  return entries;
93  }
94  }
95 }
static void View(string bundlePath)
List the specified bundle to a txt file and opens it.
Utility class to manipulate storage and bundles.
System.IO.File File
Object Database Backend (ODB) implementation that bundles multiple chunks into a .bundle files, optionally compressed with LZ4.
Description of a bundle: header, dependencies, objects and assets.
A hash to uniquely identify data.
Definition: ObjectId.cs:13
List< KeyValuePair< string, ObjectId > > Assets
const string BundleExtension
The bundle file extension.
override string ToString()
Description of an object entry in the bundle.