Пример #1
0
        public void Extract(Stream stream)
        {
            var args = new EntryExtractEventArgs {
                Entry          = this,
                ProcessedSoFar = 0
            };

            OnExtract(args);
            if (!IsDirectory)
            {
                OperationFlags flags = OperationFlags.None;
                IntPtr         file  = IntPtr.Zero;
                try {
                    file = Native.zip_fopen_index(archive.ArchivePointer, Index, flags);
                    if (file == IntPtr.Zero)
                    {
                        throw archive.GetErrorException();
                    }
                    DoExtract(file, stream, args);
                }
                finally {
                    if (file != IntPtr.Zero)
                    {
                        Native.zip_fclose(file);
                    }
                }
            }
            OnExtract(args);
        }
Пример #2
0
        public IList <ExtraField> GetExtraField(ushort fieldID, ZipHeaderLocation location = ZipHeaderLocation.Any, bool required = false)
        {
            OperationFlags flags = OperationFlags.None;

            if (!TranslateLocation(location, out flags))
            {
                return(null);
            }
            var ret = new List <ExtraField> ();

            if (flags == OperationFlags.None)
            {
                GatherExtraFields(GetFieldCount(fieldID, location, OperationFlags.Local), fieldID, OperationFlags.Local, ret, required);
                if (location == ZipHeaderLocation.Any && ret.Count > 0)
                {
                    return(ret);
                }
                GatherExtraFields(GetFieldCount(fieldID, location, OperationFlags.Central), fieldID, OperationFlags.Central, ret, required);
            }
            else
            {
                GatherExtraFields(GetFieldCount(fieldID, location, flags), fieldID, flags, ret, required);
            }

            return(ret.Count > 0 ? ret : null);
        }
Пример #3
0
        bool TranslateLocation(ZipHeaderLocation location, out OperationFlags flags)
        {
            flags = OperationFlags.None;
            switch (location)
            {
            case ZipHeaderLocation.Both:
            case ZipHeaderLocation.Any:
                if (localExtraFieldsCount <= 0 && centralExtraFieldsCount <= 0)
                {
                    return(false);
                }
                // Don't set any flags here, native api errors out if it has both central and local flags set
                break;

            case ZipHeaderLocation.Central:
                if (centralExtraFieldsCount <= 0)
                {
                    return(false);
                }
                flags = OperationFlags.Central;
                break;

            case ZipHeaderLocation.Local:
                if (localExtraFieldsCount <= 0)
                {
                    return(false);
                }
                flags = OperationFlags.Local;
                break;
            }

            return(true);
        }
Пример #4
0
        public static Int64 zip_name_locate(IntPtr archive, string fname, OperationFlags flags)
        {
            var utfFname = Utilities.StringToUtf8StringPtr(fname);

            try {
                return(zip_name_locate(archive, utfFname, flags));
            } finally {
                Utilities.FreeUtf8StringPtr(utfFname);
            }
        }
Пример #5
0
        public static int zip_stat(IntPtr archive, string fname, OperationFlags flags, out zip_stat_t sb)
        {
            var utfFname = Utilities.StringToUtf8StringPtr(fname);

            try {
                return(zip_stat(archive, utfFname, flags, out sb));
            } finally {
                Utilities.FreeUtf8StringPtr(utfFname);
            }
        }
Пример #6
0
        ushort GetFieldCount(ushort fieldID, ZipHeaderLocation location, OperationFlags flags)
        {
            short count = Native.zip_file_extra_fields_count_by_id(archive.ArchivePointer, Index, fieldID, flags);

            if (count < 0)
            {
                count = 0;
            }
            return((ushort)count);
        }
Пример #7
0
        public static Int64 zip_file_add(IntPtr archive, string name, IntPtr source, OperationFlags flags)
        {
            IntPtr utfName = Utilities.StringToUtf8StringPtr(name);

            try {
                return(zip_file_add(archive, utfName, source, flags));
            } finally {
                Utilities.FreeUtf8StringPtr(utfName);
            }
        }
Пример #8
0
 private void Record(string cmdTitle, string cmdBody, OperationFlags operation)
 {
     if (RecordAction != null)
     {
         if (operation == (operation & OperationFlag))
         {
             RecordAction(cmdTitle);
             RecordAction(cmdBody);
         }
     }
 }
Пример #9
0
    public bool Initialize(string familyName, FluidInfo baseInfo, FluidRenderer renderer)
    {
        this.familyName = familyName;
        string result = null;

        BeginSimulatorProfilerSample();
        Profiler.BeginSample("Initialize");

        if (baseInfo == null)
        {
            result = "Attempting to initialize FluidSimulator without valid info";
        }
        fluidParameters     = baseInfo.fluidParameters;
        cellParameters      = baseInfo.cellParameters;
        operationParameters = baseInfo.operationParameters;
        operationFlags      = baseInfo.operationFlags;

        if (string.IsNullOrEmpty(result) && this.renderer != null)
        {
            result = "Attempting to re-initialize a FluidSimulator";
        }

        if (string.IsNullOrEmpty(result))
        {
            cellParameters.cellSize   = fluidParameters.physicalSize / fluidParameters.gridSize;
            fluidParameters.container = fluidParameters.container ?? transform;
            // TODO Renderer stuff should probably just be handled by the dispatcher ... if simulator and renderer can be complete ignorant of each other, that would be best. This may not be possible as the Collider depends on both the renderer and the simulator.
            this.renderer = renderer;
            this.renderer.transform.parent = fluidParameters.container;
            this.renderer.gameObject.name  = string.Format("{0} Renderer", familyName);
            result = this.renderer.Initialize(this, baseInfo);
        }

        Profiler.BeginSample("InitializeBuffers");
        result = initializeBuffers();
        if (!string.IsNullOrEmpty(result))
        {
            EndSimulatorProfilerSample();
            result = string.Format("Failed to initialize buffers: {0}", result);
        }

        Profiler.EndSample();
        EndSimulatorProfilerSample();

        if (!string.IsNullOrEmpty(result))
        {
            Debug.LogError(result);
            return(false);
        }

        return(true);
    }
Пример #10
0
        public NameServicePacketHeader(byte[] buffer, int offset)
        {
            TransactionID = BigEndianConverter.ToUInt16(buffer, offset + 0);
            ushort temp = BigEndianConverter.ToUInt16(buffer, offset + 2);

            ResultCode = (byte)(temp & 0xF);
            Flags      = (OperationFlags)((temp >> 4) & 0x7F);
            OpCode     = (NameServiceOperation)((temp >> 11) & 0x1F);
            QDCount    = BigEndianConverter.ToUInt16(buffer, offset + 4);
            ANCount    = BigEndianConverter.ToUInt16(buffer, offset + 6);
            NSCount    = BigEndianConverter.ToUInt16(buffer, offset + 8);
            ARCount    = BigEndianConverter.ToUInt16(buffer, offset + 10);
        }
Пример #11
0
        public bool ExtraFieldPresent(ushort fieldID, ZipHeaderLocation location = ZipHeaderLocation.Any)
        {
            OperationFlags flags = OperationFlags.None;

            if (!TranslateLocation(location, out flags))
            {
                return(false);
            }

            if (flags != OperationFlags.Central && GetFieldCount(fieldID, location, OperationFlags.Local) > 0)
            {
                return(true);
            }
            return(GetFieldCount(fieldID, location, OperationFlags.Central) > 0);
        }
Пример #12
0
        IntPtr OpenArchive(string password, OperationFlags flags)
        {
            IntPtr file;

            if (!String.IsNullOrWhiteSpace(password))
            {
                file = Native.zip_fopen_index_encrypted(archive.ArchivePointer, Index, flags, password);
            }
            else
            {
                file = Native.zip_fopen_index(archive.ArchivePointer, Index, flags);
            }

            return(file);
        }
Пример #13
0
        /// <summary>
        /// Extract this entry in directory specified by <paramref name="destinationDir"/>, optionally changing the entry's name to the
        /// one given in <paramref name="destinationFileName"/>. The destination file is opened using mode specified in the
        /// <paramref name="outputFileMode"/> parameter.
        /// </summary>
        /// <param name="destinationDir">Destination dir.</param>
        /// <param name="destinationFileName">Destination file name.</param>
        /// <param name="outputFileMode">Output file mode.</param>
        /// <param name="useNativeFileName">Make sure that the file name is converted to the operating system
        /// native format before extracting</param>
        /// <param name="password">Password of the ZipEntry</param>
        public string Extract(string destinationDir = null, string destinationFileName = null, FileMode outputFileMode = FileMode.Create, bool useNativeFileName = false, string password = null)
        {
            destinationDir = destinationDir?.Trim();
            if (String.IsNullOrEmpty(destinationDir))
            {
                destinationDir = String.IsNullOrEmpty(archive.DefaultExtractionDir) ? "." : archive.DefaultExtractionDir;
            }
            destinationFileName = destinationFileName?.Trim();
            string name = useNativeFileName ? NativeFullName : FullName;
            string path = Path.Combine(destinationDir, String.IsNullOrEmpty(destinationFileName) ? name : destinationFileName);
            string dir  = Path.GetDirectoryName(path);

            Directory.CreateDirectory(dir);

            var args = new EntryExtractEventArgs {
                Entry          = this,
                ProcessedSoFar = 0
            };

            OnExtract(args);
            if (!IsDirectory)
            {
                // TODO: handle non-regular files
                OperationFlags flags = OperationFlags.None;
                IntPtr         file  = IntPtr.Zero;
                try {
                    file = OpenArchive(password, flags);
                    if (file == IntPtr.Zero)
                    {
                        throw archive.GetErrorException();
                    }
                    DoExtract(file, path, outputFileMode, args);
                    PlatformServices.Instance.SetFileProperties(this, path, true);
                } finally {
                    if (file != IntPtr.Zero)
                    {
                        Native.zip_fclose(file);
                    }
                }
            }
            OnExtract(args);

            return(path);
        }
Пример #14
0
        void GatherExtraFields(ushort count, ushort fieldID, OperationFlags flags, List <ExtraField> fields, bool required)
        {
            if (count == 0)
            {
                return;
            }

            ushort fieldLength;
            IntPtr fieldData;

            for (ushort i = 0; i < count; i++)
            {
                fieldData = Native.zip_file_extra_field_get_by_id(archive.ArchivePointer, Index, fieldID, (ushort)i, out fieldLength, flags);
                if (fieldData == IntPtr.Zero)
                {
                    if (!required)
                    {
                        continue;
                    }
                    throw archive.GetErrorException();
                }

                byte [] data;
                if (fieldLength > 0)
                {
                    data = new byte [fieldLength];
                    Marshal.Copy(fieldData, data, 0, fieldLength);
                }
                else
                {
                    data = null;
                }

                fields.Add(new ExtraField {
                    RawData    = data,
                    EntryIndex = Index,
                    FieldIndex = i,
                    ID         = fieldID,
                    Local      = true,
                    Length     = fieldLength
                });
            }
        }
 public void PressBinaryOperation(OperationFlags operation)
 {
     switch (_operationFlag)
     {
         case OperationFlags.Add:
             _mainRegister.Add(_auxRegitser, _mainRegister);
             break;
         case OperationFlags.Sub:
             _mainRegister.Sub(_auxRegitser, _mainRegister);
             break;
         case OperationFlags.Mul:
             _mainRegister.Mul(_auxRegitser, _mainRegister);
             break;
         case OperationFlags.Div:
             _mainRegister.Div(_auxRegitser, _mainRegister);
             break;
     }
     _operationFlag = operation;
     _flush = true;
     _resetScan = true;
 }
Пример #16
0
 public static extern int zip_file_replace(IntPtr archive, UInt64 index, IntPtr source, OperationFlags flags);
Пример #17
0
 public static extern int zip_get_archive_flag(IntPtr archive, ArchiveGlobalFlags flag, OperationFlags flags);
Пример #18
0
 public static extern IntPtr zip_get_name_ptr(IntPtr archive, UInt64 index, OperationFlags flags);
Пример #19
0
 public static string zip_get_name(IntPtr archive, UInt64 index, OperationFlags flags)
 {
     return(Utilities.Utf8StringPtrToString(zip_get_name_ptr(archive, index, flags)));
 }
Пример #20
0
 public static extern Int64 zip_name_locate(IntPtr archive, IntPtr fname, OperationFlags flags);
Пример #21
0
 public static extern int zip_file_set_external_attributes(IntPtr archive, UInt64 index, OperationFlags flags, byte opsys, UInt32 attributes);
Пример #22
0
 public static extern IntPtr zip_file_extra_field_get_by_id(IntPtr archive, UInt64 index, UInt16 extra_field_id, UInt16 extra_field_index, out UInt16 lenp, OperationFlags flags);
Пример #23
0
 public static extern int zip_file_extra_field_set(IntPtr archive, UInt64 index, UInt16 extra_field_id, UInt16 extra_field_index, byte[] extra_field_data, UInt16 len, OperationFlags flags);
Пример #24
0
 public static extern Int64 zip_get_num_entries(IntPtr archive, OperationFlags flags);
Пример #25
0
 public static extern Int64 zip_file_add(IntPtr archive, IntPtr name, IntPtr source, OperationFlags flags);
Пример #26
0
 public static extern Int16 zip_file_extra_fields_count_by_id(IntPtr archive, UInt64 index, UInt16 extra_field_id, OperationFlags flags);
Пример #27
0
 public static int zip_file_extra_field_set(IntPtr archive, UInt64 index, UInt16 extra_field_id, UInt16 extra_field_index, byte[] extra_field_data, OperationFlags flags)
 {
     return(zip_file_extra_field_set(archive, index, extra_field_id, extra_field_index, extra_field_data, (UInt16)(extra_field_data == null ? 0 : extra_field_data.Length), flags));
 }
Пример #28
0
 public static extern int zip_set_file_comment(IntPtr archive, UInt64 index, IntPtr comment, UInt16 len, OperationFlags flags);
Пример #29
0
        public static int zip_set_file_comment(IntPtr archive, UInt64 index, string comment, UInt16 len, OperationFlags flags)
        {
            IntPtr utfComment = Utilities.StringToUtf8StringPtr(comment);

            try {
                return(zip_set_file_comment(archive, index, utfComment, len, flags));
            } finally {
                Utilities.FreeUtf8StringPtr(utfComment);
            }
        }
Пример #30
0
 public static extern Int64 zip_dir_add(IntPtr archive, IntPtr name, OperationFlags flags);
Пример #31
0
 public static extern int zip_file_extra_field_delete_by_id(IntPtr archive, UInt64 index, UInt16 extra_field_id, UInt16 extra_field_index, OperationFlags flags);