public Deck Deserialize(FsPath file, FsPath dir) { State.LastLoadedFile = file; Deck deck = Deck.Create(); deck.File = file; int maxLen = 0x8000000; // 128 MB long length = file.File().Length; if (length > maxLen) { deck.Error = $"File size {length} bytes exceeds maximum of {maxLen} bytes"; return(deck); } string serialized; try { serialized = file.ReadAllText(); } catch (IOException ex) { deck.Error = ex.Message; return(deck); } var format = @"*" + file.Extension(); var formatter = getFormatter(format, serialized); if (formatter == null) { deck.Error = "Deck format is not supported"; return(deck); } deck = LoadSerialized(format, serialized, exact: false); deck.File = file; if (deck.Name == null) { string getNestedFileName() => dir.Base().Join(file.RelativeTo(dir)).Value .Replace(new string(Path.DirectorySeparatorChar, 1), Environment.NewLine); var extension = file.Extension(); string nameBase = !dir.HasValue() ? file.Basename() : getNestedFileName(); deck.Name = nameBase.Substring(0, nameBase.Length - extension.Length); } return(deck); }