/// <summary> /// Imports map from file specified by FileName (property of this model). /// Ef error occurs, returns false, otherwise true. /// </summary> /// <returns>True if map was imported.</returns> private bool ImportMapFromFile(string fileName) { if (fileName == null || !File.Exists(fileName)) { return(false); } try { byte[] fileContent; fileContent = File.ReadAllBytes(fileName); Map deserializedMap = new BinaryMapSerializer().Deserialize(fileContent); ImportedMaps.Add(new ImportedMapWrapper() { Map = deserializedMap, FilePath = fileName }); return(true); } catch (Exception ex) { return(false); } }
/// <summary> /// Tries to load maps from MAP_FOLDER_NAME directory which is supposed so be in the same place as executable. /// </summary> private void LoadMaps() { string mapsPath = Directory.GetCurrentDirectory() + "\\" + GlobalConfiguration.MAP_FOLDER_NAME; if (!Directory.Exists(mapsPath)) { return; } ImportedMaps.Clear(); int failedMaps = 0; foreach (string filePath in Directory.GetFiles(mapsPath)) { if (!ImportMapFromFile(filePath)) { failedMaps++; } } FailedMaps = failedMaps; }