Ejemplo n.º 1
0
        public override bool CanLoadObject(string path)
        {
            path = path.ToLowerInvariant();
            if (path.EndsWith(".b3d") || path.EndsWith(".csv"))
            {
                if (System.IO.File.Exists(path) && FileFormats.IsNautilusFile(path))
                {
                    return(false);
                }
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
 /// <summary>Checks whether the plugin can load the specified texture.</summary>
 /// <param name="path">The path to the file or folder that contains the texture.</param>
 /// <returns>Whether the plugin can load the specified texture.</returns>
 public override bool CanLoadTexture(string path)
 {
     if (File.Exists(path))
     {
         if (FileFormats.IsNautilusFile(path))
         {
             return(false);
         }
         using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) {
             using (BinaryReader reader = new BinaryReader(stream)) {
                 if (stream.Length < 8)
                 {
                     return(false);
                 }
                 uint identifier1 = reader.ReadUInt32();
                 uint identifier2 = reader.ReadUInt32();
                 if ((identifier1 & 0xFFFF) == 0x4D42)
                 {
                     /* BMP */
                     return(true);
                 }
                 else if (identifier1 == 0x38464947 & ((identifier2 & 0xFFFF) == 0x6137 | (identifier2 & 0xFFFF) == 0x6139))
                 {
                     /* GIF */
                     return(true);
                 }
                 else if (identifier1 == 0xE0FFD8FF | identifier1 == 0xE1FFD8FF)
                 {
                     /* JPEG */
                     return(true);
                 }
                 else if (identifier1 == 0x474E5089 & identifier2 == 0x0A1A0A0D)
                 {
                     /* PNG */
                     return(true);
                 }
                 else if (identifier1 == 0x002A4949 | identifier1 == 0x2A004D4D)
                 {
                     /* TIFF */
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
        public override bool CanLoadObject(string path)
        {
            if (string.IsNullOrEmpty(path) || !File.Exists(path))
            {
                return(false);
            }
            if (path.EndsWith(".b3d", StringComparison.InvariantCultureIgnoreCase) || path.ToLowerInvariant().EndsWith(".csv", StringComparison.InvariantCultureIgnoreCase))
            {
                if (File.Exists(path) && FileFormats.IsNautilusFile(path))
                {
                    return(false);
                }

                bool currentlyLoading = false;

                if (currentHost.Application != HostApplication.ObjectViewer)
                {
                    for (int i = 0; i < currentHost.Plugins.Length; i++)
                    {
                        if (currentHost.Plugins[i].Route != null && currentHost.Plugins[i].Route.IsLoading || currentHost.Plugins[i].Train != null && currentHost.Plugins[i].Train.IsLoading)
                        {
                            currentlyLoading = true;
                            break;
                        }
                    }
                }

                try
                {
                    using (StreamReader fileReader = new StreamReader(path))
                    {
                        for (int i = 0; i < 100; i++)
                        {
                            try
                            {
                                string readLine = fileReader.ReadLine();
                                if (!string.IsNullOrEmpty(readLine) && readLine.IndexOf("meshbuilder", StringComparison.InvariantCultureIgnoreCase) != -1)
                                {
                                    //We have found the MeshBuilder statement within the first 100 lines
                                    //This must be an object (we hope)
                                    //Use a slightly larger value than for routes, as we're hoping for a positive match
                                    return(true);
                                }
                            }
                            catch
                            {
                                //ignored
                            }
                        }
                    }
                }
                catch
                {
                    return(false);
                }

                if (currentlyLoading)
                {
                    /*
                     * https://github.com/leezer3/OpenBVE/issues/666
                     * https://github.com/leezer3/OpenBVE/issues/661
                     *
                     * In BVE routes, a null (empty) object may be used
                     * in circumstances where we want a rail / wall / ground etc.
                     * to continue, but show nothing
                     *
                     * These have no set format, and likely are undetectable, especially
                     * if they're an empty file in the first place.....
                     *
                     * However, we *still* want to be able to detect that we can't load a file
                     * and pass it off to Object Viewer if it thinks it can handle it, so we need to
                     * know if a Route Plugin is loading (if so, it must be a null object) versus not-
                     * Don't do anything
                     *
                     * TODO: Add a way to have 'proper' empty railtypes without this kludge and add appropriate info message here
                     */

                    return(true);
                }
            }
            return(false);
        }