예제 #1
0
        public bool IsValidFile(Stream inputStream, CartridgeFileFormat targetFormat)
        {
            if (targetFormat != CartridgeFileFormat.GWC)
            {
                throw new InvalidOperationException("FileGWC does not support other formats than GWC.");
            }

            return(GetFileFormat(inputStream) == CartridgeFileFormat.GWC);
        }
예제 #2
0
        /// <summary>
        /// Load a cartridge file of unkown type into an Cartridge object.
        /// </summary>
        /// <param name="inputStream">Stream containing the cartridge file.</param>
        /// <param name="cart">Cartridge object, which should be used.</param>
        public static void Load(Stream inputStream, Cartridge cart)
        {
            // Gets the first loader that can load the stream.
            CartridgeFileFormat fFormat = GetFileFormat(inputStream);
            ICartridgeLoader    loader  = _loaders.FirstOrDefault(icl => icl.CanLoad(fFormat));

            if (loader == null)
            {
                throw new InvalidOperationException("The file format is not supported.");
            }

            // Loads the cartridge.
            loader.Load(inputStream, cart);
        }
예제 #3
0
        /// <summary>
        /// Get FileFormat from a stream.
        /// </summary>
        /// <param name="inputStream">Stream, which holds the file to check.</param>
        /// <returns>FileFormat of given stream.</returns>
        public static CartridgeFileFormat GetFileFormat(Stream inputStream)
        {
            CartridgeFileFormat current = CartridgeFileFormat.Unknown;

            foreach (ICartridgeLoader loader in _loaders)
            {
                // Gets the file format.
                current = loader.GetFileFormat(inputStream);

                // Returns it if it's not unknown.
                if (current != CartridgeFileFormat.Unknown)
                {
                    return(current);
                }
            }

            return(CartridgeFileFormat.Unknown);
        }
예제 #4
0
		public bool IsValidFile(Stream inputStream, CartridgeFileFormat targetFormat)
		{
			if (targetFormat != CartridgeFileFormat.GWC)
				throw new InvalidOperationException("FileGWC does not support other formats than GWC.");

			return GetFileFormat(inputStream) == CartridgeFileFormat.GWC;
		}
예제 #5
0
		/*
		 File format of GWC files:

		@0000:							; Signature
			BYTE	 0x02
			BYTE	 0x0a
			BYTE	 "CART"
			BYTE	 0x00

		@0007:
			USHORT	 NumberOfObjects	; Number of objects ("media files") in cartridge:

		@0009:
			; References to individual objects in cartridge.
			; Object 0 is always Lua bytecode for cartridge.
			; There is exactly [number_of_objects] blocks like this:
			repeat <NumberOfObjects> times
			{
				USHORT	 ObjectID		; Distinct ID for each object, duplicates are forbidden
				INT		 Address		; Address of object in GWC file
			}

		@xxxx:	 						; 0009 + <NumberOfObjects> * 0006 bytes from begining
			; Header with all important informations for this cartridge
			INT		 HeaderLength		; Length of information header (following block):

			DOUBLE	 Latitude			; N+/S-
			DOUBLE	 Longitude			; E+/W-
			DOUBLE	 Altitude			; Meters

			LONG	 Date of creation	; Seconds since 2004-02-10 01:00:00

			; MediaID of icon and splashscreen
			SHORT	 ObjectID of splashscreen	 ; -1 = without splashscreen/poster
			SHORT	 ObjectID of icon			 ; -1 = without icon

			ASCIIZ	 TypeOfCartridge			 ; "Tour guide", "Wherigo cache", etc.
			ASCIIZ	 Player						 ; Name of player downloaded cartridge
			LONG	 PlayerID					 ; ID of player in the Groundspeak database

			ASCIIZ	 CartridgeName				 ; "Name of this cartridge"
			ASCIIZ	 CartridgeGUID
			ASCIIZ	 CartridgeDescription		 ; "This is a sample cartridge"
			ASCIIZ	 StartingLocationDescription ; "Nice parking"
			ASCIIZ	 Version					 ; "1.2"
			ASCIIZ	 Author						 ; Author of cartridge
			ASCIIZ	 Company					 ; Company of cartridge author
			ASCIIZ	 RecommendedDevice			 ; "Garmin Colorado", "Windows PPC", etc.

			INT		 Length						 ; Length of CompletionCode
			ASCIIZ	 CompletionCode				 ; Normally 15/16 characters

		@address_of_FIRST_object (with ObjectID = 0):
			; always Lua bytecode
			INT		 Length						 ; Length of Lua bytecode
			BYTE[Length]	ContentOfObject		 ; Lua bytecode

		@address_of_ALL_OTHER_objects (with ID > 0):
			BYTE	 ValidObject
			if (ValidObject == 0)
			{
				; when ValidObject == 0, it means that object is DELETED and does
				; not exist in cartridge. Nothing else follows.
			}
			else
			{
				INT		ObjectType				 ; 1=bmp, (2=png?), 3=jpg, 4=gif, 17=wav, 18=mp3, 19=fdl, other values have unknown meaning
				INT	 	Length
				BYTE[Length]	content_of_object
			}

		@end

		Varibles

			BYTE   = unsigned char (1 byte)
			SHORT  = signed short (2 bytes)
			USHORT = unsigned short (2 bytes)
			INT	   = signed long (4 bytes)
			UINT   = unsigned long (4 bytes)
			LONG   = signed long (8 bytes)
			DOUBLE = double-precision floating point number (8 bytes)
			ASCIIZ = zero-terminated string ("hello world!", 0x00)
		*/

		public bool CanLoad(CartridgeFileFormat targetFileType)
		{
			return targetFileType == CartridgeFileFormat.GWC;
		}
예제 #6
0
        /*
         * File format of GWC files:
         *
         * @0000:							; Signature
         *      BYTE	 0x02
         *      BYTE	 0x0a
         *      BYTE	 "CART"
         *      BYTE	 0x00
         *
         * @0007:
         *      USHORT	 NumberOfObjects	; Number of objects ("media files") in cartridge:
         *
         * @0009:
         *      ; References to individual objects in cartridge.
         *      ; Object 0 is always Lua bytecode for cartridge.
         *      ; There is exactly [number_of_objects] blocks like this:
         *      repeat <NumberOfObjects> times
         *      {
         *              USHORT	 ObjectID		; Distinct ID for each object, duplicates are forbidden
         *              INT		 Address		; Address of object in GWC file
         *      }
         *
         * @xxxx:	                        ; 0009 + <NumberOfObjects> * 0006 bytes from begining
         *      ; Header with all important informations for this cartridge
         *      INT		 HeaderLength		; Length of information header (following block):
         *
         *      DOUBLE	 Latitude			; N+/S-
         *      DOUBLE	 Longitude			; E+/W-
         *      DOUBLE	 Altitude			; Meters
         *
         *      LONG	 Date of creation	; Seconds since 2004-02-10 01:00:00
         *
         *      ; MediaID of icon and splashscreen
         *      SHORT	 ObjectID of splashscreen	 ; -1 = without splashscreen/poster
         *      SHORT	 ObjectID of icon			 ; -1 = without icon
         *
         *      ASCIIZ	 TypeOfCartridge			 ; "Tour guide", "Wherigo cache", etc.
         *      ASCIIZ	 Player						 ; Name of player downloaded cartridge
         *      LONG	 PlayerID					 ; ID of player in the Groundspeak database
         *
         *      ASCIIZ	 CartridgeName				 ; "Name of this cartridge"
         *      ASCIIZ	 CartridgeGUID
         *      ASCIIZ	 CartridgeDescription		 ; "This is a sample cartridge"
         *      ASCIIZ	 StartingLocationDescription ; "Nice parking"
         *      ASCIIZ	 Version					 ; "1.2"
         *      ASCIIZ	 Author						 ; Author of cartridge
         *      ASCIIZ	 Company					 ; Company of cartridge author
         *      ASCIIZ	 RecommendedDevice			 ; "Garmin Colorado", "Windows PPC", etc.
         *
         *      INT		 Length						 ; Length of CompletionCode
         *      ASCIIZ	 CompletionCode				 ; Normally 15/16 characters
         *
         * @address_of_FIRST_object (with ObjectID = 0):
         *      ; always Lua bytecode
         *      INT		 Length						 ; Length of Lua bytecode
         *      BYTE[Length]	ContentOfObject		 ; Lua bytecode
         *
         * @address_of_ALL_OTHER_objects (with ID > 0):
         *      BYTE	 ValidObject
         *      if (ValidObject == 0)
         *      {
         *              ; when ValidObject == 0, it means that object is DELETED and does
         *              ; not exist in cartridge. Nothing else follows.
         *      }
         *      else
         *      {
         *              INT		ObjectType				 ; 1=bmp, (2=png?), 3=jpg, 4=gif, 17=wav, 18=mp3, 19=fdl, other values have unknown meaning
         *              INT	    Length
         *              BYTE[Length]	content_of_object
         *      }
         *
         * @end
         *
         * Varibles
         *
         *      BYTE   = unsigned char (1 byte)
         *      SHORT  = signed short (2 bytes)
         *      USHORT = unsigned short (2 bytes)
         *      INT	   = signed long (4 bytes)
         *      UINT   = unsigned long (4 bytes)
         *      LONG   = signed long (8 bytes)
         *      DOUBLE = double-precision floating point number (8 bytes)
         *      ASCIIZ = zero-terminated string ("hello world!", 0x00)
         */

        public bool CanLoad(CartridgeFileFormat targetFileType)
        {
            return(targetFileType == CartridgeFileFormat.GWC);
        }