示例#1
0
        private LoadedFile GetLF(string path, string name)
        {
            LoadedFile lf;
            string     file = System.IO.Path.Combine(_base, path, name);

            if (!_files.TryGetValue(file, out lf))
            {
                lf        = new LoadedFile();
                lf.Handle = Wrap.CreateFile(file.Replace('/', '\\'), System.IO.FileAccess.Read, System.IO.FileShare.Read, IntPtr.Zero, System.IO.FileMode.Open, System.IO.FileAttributes.Normal, IntPtr.Zero);
                if (lf.Handle == IntPtr.Zero || lf.Handle == new IntPtr(-1))
                {
                    lf.Missing = true;
                    lf.Tag     = DateTime.MaxValue;
                    System.Diagnostics.Debug.WriteLine("Passing through {0}, no override file", file, lf);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Overriding data for {0}", file, lf);
                    //System.Threading.Thread.Sleep(10000);
                    //System.Diagnostics.Debugger.Break();
                }
                _files[file] = lf;
            }
            return(lf);
        }
示例#2
0
文件: VFile.cs 项目: professorlust/7h
 public override void Read(uint offset, uint length, IntPtr dest, ref uint bytesRead)
 {
     if (_handle == IntPtr.Zero)
     {
         _handle = Wrap.CreateFile(Filename, System.IO.FileAccess.Read, System.IO.FileShare.Read, IntPtr.Zero, System.IO.FileMode.Open, System.IO.FileAttributes.Normal, IntPtr.Zero);
     }
     _access = DateTime.Now;
     Wrap.SetFilePointer(_handle, (int)offset, IntPtr.Zero, Wrap.EMoveMethod.Begin);
     Win32.ReadFile(_handle, dest, length, ref bytesRead, IntPtr.Zero);
 }
示例#3
0
文件: VFile.cs 项目: professorlust/7h
        public override void Read(uint offset, uint length, IntPtr dest, ref uint bytesRead)
        {
            //System.Diagnostics.Debug.WriteLine("Conditional {2} reading from OS {0} L {1}", offset, length, Name);

            bool header = (offset < 24);
            bool init   = (offset == 24);

            if ((!_lastHeader && header) || (init && !_lastInit))   //re-evaluate
            {
                _current = null;
                if (!_handle.Equals(IntPtr.Zero))
                {
                    Win32.CloseHandle(_handle);
                }
                _handle = IntPtr.Zero;

                foreach (var of in _files)
                {
                    if (of.CFolder == null || of.CFolder.IsActive(of.CName))
                    {
                        System.Diagnostics.Debug.WriteLine("Conditional {0} switching to {1}", Name, of.File);
                        _current = of;
                        Bytes.WriteInt(_header, 20, of.Size);
                        break;
                    }
                }
                if (_current == null)
                {
                    System.Diagnostics.Debug.WriteLine("Conditional {0} switching to fallback", Name, Name);
                }
                _lastInit = true; //we're ready to read file headers
            }
            else
            {
                _lastInit = init;
            }
            if (_current != null && _handle.Equals(IntPtr.Zero) && _current.Archive == null)
            {
                _handle = Wrap.CreateFile(_current.File, System.IO.FileAccess.Read, System.IO.FileShare.Read, IntPtr.Zero, System.IO.FileMode.Open, System.IO.FileAttributes.Normal, IntPtr.Zero);
            }
            _lastHeader = header;
            _access     = DateTime.Now;

            if (_current == null)   //read from fallback
            //System.Diagnostics.Debug.WriteLine("Conditional reading from fallback handle {0} with extra offset {1}", _fallbackHandle, _fallbackOffset);
            {
                Win32.OVERLAPPED ov = new Win32.OVERLAPPED()
                {
                    EventHandle  = IntPtr.Zero,
                    Internal     = UIntPtr.Zero,
                    InternalHigh = UIntPtr.Zero,
                    Offset       = _fallbackOffset + offset,
                    OffsetHigh   = 0
                };
                Win32.ReadFile(_fallbackHandle, dest, length, ref bytesRead, ref ov);
                //System.Diagnostics.Debug.WriteLine("Conditional {1} reading from fallback - {0} bytes read", bytesRead, Name);
            }
            else
            {
                if (offset < 24)
                {
                    length = Math.Min(length, 24 - offset);
                    System.Runtime.InteropServices.Marshal.Copy(_header, (int)offset, dest, (int)length);
                    bytesRead = length;
                    //System.Diagnostics.Debug.WriteLine("Conditional {2} reading from cheader - {0} bytes read [current size is {1}]", bytesRead, BitConverter.ToInt32(_header, 20), Name);
                    return;
                }
                else
                {
                    offset -= 24;
                    if (_current.Archive == null)
                    {
                        Wrap.SetFilePointer(_handle, (int)offset, IntPtr.Zero, Wrap.EMoveMethod.Begin);
                        Win32.ReadFile(_handle, dest, length, ref bytesRead, IntPtr.Zero);
                        //System.Diagnostics.Debug.WriteLine("Conditional {1} reading from cfile - {0} bytes read", bytesRead, Name);
                    }
                    else
                    {
                        _current.Archive.RawRead(_current.File, offset, length, dest, ref bytesRead);
                        //System.Diagnostics.Debug.WriteLine("Conditional {1} reading from cfile archive offset {2} length {3} - {0} bytes read", bytesRead, Name, offset, length);
                    }
                }
            }
        }