6 using System.Text.RegularExpressions;
7 using SiliconStudio.Core.Storage;
8 using SiliconStudio.Core.IO;
9 using System.Collections.Generic;
13 namespace SiliconStudio.Core.Serialization.Assets
17 private static Regex RegexEntry =
new Regex(
@"^(.*?)\s+(\w+)$");
26 if (
string.IsNullOrWhiteSpace(indexName))
34 result.stream = VirtualFileSystem.OpenStream(
35 "/data/db/" + indexName,
36 VirtualFileMode.OpenOrCreate,
37 VirtualFileAccess.ReadWrite,
38 VirtualFileShare.ReadWrite);
43 public static AssetIndexMap Load(
string indexFile =
"/data/db/index",
bool isReadOnly =
false)
45 if (indexFile == null)
throw new ArgumentNullException(
"indexFile");
49 var isAppDataWriteable = !isReadOnly;
50 if (isAppDataWriteable)
55 result.stream = VirtualFileSystem.OpenStream(
57 VirtualFileMode.OpenOrCreate,
58 VirtualFileAccess.ReadWrite,
59 VirtualFileShare.ReadWrite);
61 catch (UnauthorizedAccessException)
63 isAppDataWriteable =
false;
67 if (!isAppDataWriteable)
70 result.stream = VirtualFileSystem.OpenStream(
73 VirtualFileAccess.Read);
76 result.LoadNewValues();
85 return GetPendingItems(transaction);
94 .Select(x =>
new KeyValuePair<string, ObjectId>(x.Key, x.Value.Value))
95 .Concat(loadedIdMap.Where(x => !unsavedIdMap.ContainsKey(x.Key)))
100 protected override List<KeyValuePair<string, ObjectId>>
ReadEntries(System.IO.Stream localStream)
104 var entries =
new List<KeyValuePair<string, ObjectId>>();
105 while ((line = reader.ReadLine()) != null)
108 if (line ==
string.Empty || line.StartsWith(
"#"))
111 var match = RegexEntry.Match(line);
114 throw new InvalidOperationException(
"Unable to read asset index entry [{0}]. Expecting: [path objectId]".ToFormat(line));
117 var url = match.Groups[1].Value;
118 var objectIdStr = match.Groups[2].Value;
123 throw new InvalidOperationException(
"Unable to decode objectid [{0}] when reading asset index".ToFormat(objectIdStr));
126 var entry =
new KeyValuePair<string, ObjectId>(url, objectId);
134 var line = string.Format(
"{0} {1}\n", value.Key, value.Value);
135 var bytes = Encoding.UTF8.GetBytes(line);
136 stream.Write(bytes, 0, bytes.Length);
override List< KeyValuePair< string, ObjectId > > ReadEntries(System.IO.Stream localStream)
IEnumerable< KeyValuePair< string, ObjectId > > GetMergedIdMap()
System.Text.Encoding Encoding
override void WriteEntry(Stream stream, KeyValuePair< string, ObjectId > value)
A hash to uniquely identify data.
static AssetIndexMap Load(string indexFile="/data/db/index", bool isReadOnly=false)
static bool TryParse(string input, out ObjectId result)
Tries to parse an ObjectId from a string.
IEnumerable< KeyValuePair< string, ObjectId > > GetTransactionIdMap()
static AssetIndexMap NewTool(string indexName=null)