/// <summary>Loads the specified route.</summary> /// <param name="path">The path to the file or folder that contains the route.</param> /// <param name="Encoding">The user-selected encoding (if appropriate)</param> /// <param name="trainPath">The path to the selected train</param> /// <param name="objectPath">The base object folder path</param> /// <param name="soundPath">The base sound folder path</param> /// <param name="PreviewOnly">Whether this is a preview</param> /// <param name="route">Receives the route.</param> /// <returns>Whether loading the sound was successful.</returns> public override bool LoadRoute(string path, Encoding Encoding, string trainPath, string objectPath, string soundPath, bool PreviewOnly, ref object route) { if (Encoding == null) { Encoding = Encoding.UTF8; } LastException = null; Cancel = false; CurrentProgress = 0.0; IsLoading = true; FileSystem.AppendToLogFile("Loading route file: " + path); FileSystem.AppendToLogFile("INFO: Route file hash " + Path.GetChecksum(path)); CurrentRoute = (CurrentRoute)route; //First, check the format of the route file //RW routes were written for BVE1 / 2, and have a different command syntax bool isRw = path.ToLowerInvariant().EndsWith(".rw"); FileSystem.AppendToLogFile("Route file format is: " + (isRw ? "RW" : "CSV")); try { Parser parser = new Parser(); parser.ParseRoute(path, isRw, Encoding, trainPath, objectPath, soundPath, PreviewOnly, this); IsLoading = false; return(true); } catch (Exception ex) { route = null; CurrentHost.AddMessage(MessageType.Error, false, "An unexpected error occured whilst attempting to load the following routefile: " + path); IsLoading = false; LastException = ex; return(false); } }
/// <summary>Checks whether the plugin can load the specified route.</summary> /// <param name="path">The path to the file or folder that contains the route.</param> /// <returns>Whether the plugin can load the specified route.</returns> public override bool CanLoadRoute(string path) { if (!File.Exists(path)) { return(false); } if (path.EndsWith(".dat", StringComparison.InvariantCultureIgnoreCase)) { try { if (Parser.knownModules.Contains(Path.GetChecksum(path)) || File.ReadLines(path).Count() < 800) { /* * Slightly hacky check if not found in the known modules list: * The original Mechanik download contained a route generator. * All this did was to append various module files to generate a * final route. * * If we have less than ~800 lines, it's not a complete route, but * a module instead. */ return(false); } } catch { //Innacessable file?! return(false); } return(true); } return(false); }