/// <summary> /// Initializes a new instance with the specified values. /// </summary> /// <param name="resourceFileName">The path to the resource file to use</param> public ResourceFileResourceAccessor(string resourceFileName) : base(null) { // NOTE we need to support a null filename here since the class is also // used to obtain the resource names during resource file generation // (during which the output file doesn't yet exist) _FileName = resourceFileName; _ResourceData = null; }
public FilePackage(string path, bool newfile = false) { File = new FileInfo(path); if (newfile) { Package = new ToePackage(); } else { Package = new ToePackage(File.Open(FileMode.Open)); } ResourceFileData = new ResourceFileData(Package); }
/// <summary> /// Initializes a new instance, using default values. The path to the resource file /// is determined by a search heuristics which searches several standard locations in which /// the resource file may be located. The usual location is the where the current assembly /// is located. An exception is thrown if the resource file isn't found. /// </summary> public ResourceFileResourceAccessor() : base(null) { try { string loc = GetResourceFile(); // TODO check whether file has changed? (timestamp, size) _FileName = loc; _ResourceData = null; } catch (FileNotFoundException) { throw new Core.LanguagePlatformException(Core.ErrorCode.LanguageResourceFileNotFound, Core.FaultStatus.Fatal); } }
/// <summary> /// See <see cref="ResourceStorage.GetAllResourceKeys"/> /// </summary> /// <returns>The list of resource keys known to the storage.</returns> public override List <string> GetAllResourceKeys() { lock (_cacheLock) { if (_ResourceData == null) { if (!_Cache.TryGetValue(_FileName, out _ResourceData)) { if (!System.IO.File.Exists(_FileName)) { throw new Core.LanguagePlatformException(Core.ErrorCode.LanguageResourceFileNotFound, Core.FaultStatus.Fatal); } _ResourceData = new ResourceFileData(); _ResourceData.ResourceNames = new List <string>(); _ResourceData.Data = new Dictionary <string, byte[]>(); System.Resources.ResourceReader rdr = null; try { rdr = new System.Resources.ResourceReader(_FileName); foreach (System.Collections.DictionaryEntry entry in rdr) { _ResourceData.ResourceNames.Add((string)entry.Key); // this will effectively load all resources. Since the enumerator (which we // need to determine the available resources) also returns the data itself, // and since ResourceReader.GetResourceData() prefixes the data with an // int which contains the size of the byte array, we rather store right now: _ResourceData.Data.Add((string)entry.Key, (byte[])entry.Value); } _Cache.Add(_FileName, _ResourceData); } catch { throw new Core.LanguagePlatformException(Core.ErrorCode.InvalidLanguageResourceFile, Core.FaultStatus.Fatal); } finally { if (rdr != null) { rdr.Close(); } } } } } return(_ResourceData.ResourceNames); }