Example #1
0
        private ShaiyaDataEntry[] ReadDirs(string ParentID)
        {
            int dirCount = BitConverter.ToInt32(Buffer, Offset);

            ShaiyaDataEntry[] entrys = new ShaiyaDataEntry[dirCount];

            Offset += 4;
            if (dirCount == 0)
            {
                return(entrys);
            }

            for (int i = 0; i < dirCount; i++)
            {
                int nameLength = BitConverter.ToInt32(Buffer, Offset) - 1;                   // exclude \0
                Offset += 4;

                char[] nameChars = new char[nameLength];
                Array.Copy(Buffer, Offset, nameChars, 0, nameLength);

                Offset += nameLength + 1;                 // include \0

                entrys[i]          = new ShaiyaDataEntry(new String(nameChars), true, 0, 0, 0);
                entrys[i].ParentID = ParentID;
                mFilesFlat.Add(entrys[i].ID, entrys[i]);
                entrys[i].Entrys.AddRange(ReadFiles(entrys[i].ID));
                entrys[i].Entrys.AddRange(ReadDirs(entrys[i].ID));
            }

            return(entrys);
        }
Example #2
0
        public int GetFileCount(ShaiyaDataEntry Entry, bool Deep)
        {
            if (Entry.IsDir == false)
            {
                return(0);
            }

            int count = 0;

            foreach (ShaiyaDataEntry e in Entry.Entrys)
            {
                if (e.IsDir == false)
                {
                    count++;
                }
                else
                {
                    if (Deep == true)
                    {
                        count += GetFileCount(e);
                    }
                    else
                    {
                        count++;
                    }
                }
            }

            return(count);
        }
Example #3
0
        private ShaiyaDataEntry[] ReadFiles(string ParentID)
        {
            int fileCount = BitConverter.ToInt32(Buffer, Offset);

            ShaiyaDataEntry[] entrys = new ShaiyaDataEntry[fileCount];

            Offset += 4;
            if (fileCount == 0)
            {
                return(entrys);
            }

            for (int i = 0; i < fileCount; i++)
            {
                int nameLength = BitConverter.ToInt32(Buffer, Offset) - 1;                   // exclude \0
                Offset += 4;
                char[] nameChars = new char[nameLength];
                Array.Copy(Buffer, Offset, nameChars, 0, nameLength);

                Offset += nameLength + 1;                 // include \0

                entrys[i]              = new ShaiyaDataEntry(new String(nameChars), false, BitConverter.ToInt64(Buffer, Offset), Offset, BitConverter.ToInt32(Buffer, Offset + 8));
                entrys[i].ParentID     = ParentID;
                entrys[i].OffsetOffset = Offset;
                entrys[i].UnkownValue  = new byte[4] {
                    Buffer[Offset + 12], Buffer[Offset + 13], Buffer[Offset + 14], Buffer[Offset + 15]
                };
                mFilesFlat.Add(entrys[i].ID, entrys[i]);

                Offset += 16;
            }

            return(entrys);
        }
Example #4
0
		private void OnWriteFile( ShaiyaDataEntry Entry, int Num ) {
			if( Entry == null || Num == 100 ) {
				mWorker.CancelAsync();
				return;
			}

			mFileCount++;
			mWorker.ReportProgress( 0, Entry );
		}
Example #5
0
        public string GetRootDir(ShaiyaDataEntry baseEntry)
        {
            ShaiyaDataEntry tmpEntry = baseEntry;
            List <string>   rootDir  = new List <string>();

            while ((tmpEntry = GetFlatEntry(tmpEntry.ParentID)) != null)
            {
                rootDir.Add(tmpEntry.Filename);
            }

            rootDir.Reverse();
            return(string.Join(@"\", rootDir.ToArray()));
        }
Example #6
0
        public bool UpdateFile(string ID, string Filepath)
        {
            ShaiyaDataEntry Entry = mFilesFlat[ID];

            byte[] buf = File.ReadAllBytes(Filepath);

            // fill Buffer for newly added or updated Files
            Entry.Buffer   = buf.Clone() as byte[];
            Entry.Offset   = new FileInfo(this.BasePath + ".saf").Length;
            Entry.Length   = Entry.Buffer.Length;
            Entry.Filename = Path.GetFileName(Filepath);

            //mFiles.UpdateEntry( ID, Entry ); // referenced, no need to update *-*
            buf = null;

            return(true);
        }
Example #7
0
        public bool AddFile(ShaiyaDataEntry ParentEntry, string Filepath, out ShaiyaDataEntry NewEntry)
        {
            NewEntry = null;
            if (ParentEntry.IsDir == false)
            {
                return(false);
            }

            NewEntry          = new ShaiyaDataEntry();
            NewEntry.ParentID = ParentEntry.ID;
            NewEntry.Filename = Path.GetFileName(Filepath);
            NewEntry.Buffer   = File.ReadAllBytes(Filepath);
            NewEntry.Length   = NewEntry.Buffer.Length;
            NewEntry.Offset   = new FileInfo(this.BasePath + ".saf").Length;

            mFilesFlat.Add(NewEntry.ID, NewEntry);
            mFilesFlat[ParentEntry.ID].Entrys.Add(NewEntry);
            return(true);
        }
Example #8
0
        public bool GetData(ShaiyaDataEntry Entry, out byte[] buf)
        {
            if (Entry.Buffer != null)                // new/updated File
            {
                buf = Entry.Buffer.Clone() as byte[];
                return(true);
            }

            buf = new byte[Entry.Length];
            try {
                using (FileStream stream = File.OpenRead(BasePath + ".saf")) {
                    stream.Seek(Entry.Offset, SeekOrigin.Begin);
                    stream.Read(buf, 0, buf.Length);
                }
            } catch {
                return(false);
            }

            return(true);
        }
Example #9
0
 public int GetFileCount(ShaiyaDataEntry Entry)
 {
     return(GetFileCount(Entry, true));
 }
Example #10
0
		private ShaiyaDataEntry[] ReadDirs( string ParentID ) {
			int dirCount = BitConverter.ToInt32( Buffer, Offset );
			ShaiyaDataEntry[] entrys = new ShaiyaDataEntry[ dirCount ];

			Offset += 4;
			if( dirCount == 0 )
				return entrys;

			for( int i = 0; i < dirCount; i++ ) {
				int nameLength = BitConverter.ToInt32( Buffer, Offset ) - 1; // exclude \0
				Offset += 4;

				char[] nameChars = new char[ nameLength ];
				Array.Copy( Buffer, Offset, nameChars, 0, nameLength );

				Offset += nameLength + 1; // include \0

				entrys[ i ] = new ShaiyaDataEntry( new String( nameChars ), true, 0, 0, 0 );
				entrys[ i ].ParentID = ParentID;
				mFilesFlat.Add( entrys[ i ].ID, entrys[ i ] );
				entrys[ i ].Entrys.AddRange( ReadFiles( entrys[ i ].ID ) );
				entrys[ i ].Entrys.AddRange( ReadDirs( entrys[ i ].ID ) );

			}

			return entrys;
		}
Example #11
0
		private ShaiyaDataEntry[] ReadFiles( string ParentID ) {
			int fileCount = BitConverter.ToInt32( Buffer, Offset );
			ShaiyaDataEntry[] entrys = new ShaiyaDataEntry[ fileCount ];

			Offset += 4;
			if( fileCount == 0 )
				return entrys;

			for( int i = 0; i < fileCount; i++ ) {
				int nameLength = BitConverter.ToInt32( Buffer, Offset ) - 1; // exclude \0
				Offset += 4;
				char[] nameChars = new char[ nameLength ];
				Array.Copy( Buffer, Offset, nameChars, 0, nameLength );

				Offset += nameLength + 1; // include \0

				entrys[ i ] = new ShaiyaDataEntry( new String( nameChars ), false, BitConverter.ToInt64( Buffer, Offset ), Offset, BitConverter.ToInt32( Buffer, Offset + 8 ) );
				entrys[ i ].ParentID = ParentID;
				entrys[ i ].OffsetOffset = Offset;
				entrys[ i ].UnkownValue = new byte[ 4 ] { Buffer[ Offset + 12 ], Buffer[ Offset + 13 ], Buffer[ Offset + 14 ], Buffer[ Offset + 15 ] };
				mFilesFlat.Add( entrys[ i ].ID, entrys[ i ] );

				Offset += 16;
			}

			return entrys;
		}
Example #12
0
		public bool AddFile( ShaiyaDataEntry ParentEntry, string Filepath, out ShaiyaDataEntry NewEntry ) {
			NewEntry = null;
			if( ParentEntry.IsDir == false )
				return false;

			NewEntry = new ShaiyaDataEntry();
			NewEntry.ParentID = ParentEntry.ID;
			NewEntry.Filename = Path.GetFileName( Filepath );
			NewEntry.Buffer = File.ReadAllBytes( Filepath );
			NewEntry.Length = NewEntry.Buffer.Length;
			NewEntry.Offset = new FileInfo( this.BasePath + ".saf" ).Length;

			mFilesFlat.Add( NewEntry.ID, NewEntry );
			mFilesFlat[ ParentEntry.ID ].Entrys.Add( NewEntry );
			return true;
		}
Example #13
0
		public bool GetData( ShaiyaDataEntry Entry, out byte[] buf ) {
			if( Entry.Buffer != null ) { // new/updated File
				buf = Entry.Buffer.Clone() as byte[];
				return true;
			}

			buf = new byte[ Entry.Length ];
			try {
				using( FileStream stream = File.OpenRead( BasePath + ".saf" ) ) {
					stream.Seek( Entry.Offset, SeekOrigin.Begin );
					stream.Read( buf, 0, buf.Length );
				}
			} catch {
				return false;
			}

			return true;
		}
Example #14
0
		public int GetFileCount( ShaiyaDataEntry Entry ) {
			return GetFileCount( Entry, true );
		}
Example #15
0
		public int GetFileCount( ShaiyaDataEntry Entry, bool Deep ) {
			if( Entry.IsDir == false )
				return 0;

			int count = 0;
			foreach( ShaiyaDataEntry e in Entry.Entrys ) {
				if( e.IsDir == false )
					count++;
				else {
					if( Deep == true )
						count += GetFileCount( e );
					else
						count++;
				}
			}

			return count;
		}
Example #16
0
		public string GetRootDir( ShaiyaDataEntry baseEntry ) {
			ShaiyaDataEntry tmpEntry = baseEntry;
			List<string> rootDir = new List<string>();
			while( ( tmpEntry = GetFlatEntry( tmpEntry.ParentID ) ) != null )
				rootDir.Add( tmpEntry.Filename );

			rootDir.Reverse();
			return string.Join( @"\", rootDir.ToArray() );
		}