///// <summary>
        ///// Creates a directory, then deletes it when the test is done.
        ///// If the directory exists at the start of the test, it will be first deleted (including the files in it).
        ///// </summary>        
        //public static void CreateDirectory(TestBase test, string dir)
        //{
        //    CreateDirectory(test, dir, "Delete \"" + dir + " and every file and subfolder in the given directory \".");
        //}
        ///// <summary>
        ///// Creates a directory, then deletes it when the test is done.
        ///// If the directory exists at the start of the test, it will be first deleted (including the files in it).
        ///// Includes the option of adding to test cleanup stack or not.
        ///// </summary>        
        //public static void CreateDirectory(TestBase test, string dir, bool addToTestCleanup)
        //{
        //    CreateDirectory(test, dir, "Delete \"" + dir + " and every file and subfolder in the given directory \".", addToTestCleanup);
        //}
        ///// <summary>
        ///// Creates a directory, then deletes it when the test is done.
        ///// If the directory exists at the start of the test, it will be first deleted (including the files in it).
        ///// There is an option here to define the cleanup name
        ///// </summary>
        //public static void CreateDirectory(TestBase test, string dir, string cleanupName)
        //{
        //    CreateDirectory(test, dir, cleanupName, true);
        //}
        ///// <summary>
        ///// Creates a directory, then deletes it when the test is done.
        ///// If the directory exists at the start of the test, it will be first deleted (including the files in it).
        ///// There is an option here to define the cleanup name and also to add to cleanup stack or not.
        ///// </summary>        
        //public static void CreateDirectory(TestBase test, string dir, string cleanupName, bool addToTestCleanup)
        //{
        //    if (Directory.Exists(dir))
        //    {
        //        DeleteDirectory(true, dir);
        //    }
        //    else
        //    {
        //        Directory.CreateDirectory(dir);
        //    }
        //    if (addToTestCleanup)
        //    {
        //        // Set up cleanup
        //        test.AddTestCleanup(
        //            cleanupName,
        //            () =>
        //            {
        //                DeleteDirectory(false, dir);
        //            });
        //    }
        //}
        /// <summary>
        /// Compare the source with destination
        /// If they are the same path, do nothing
        /// Otherwise, copy everything in source to destination that doesn't already
        /// exist there, or has a different date/time or length.  Note that setting
        /// clearDestination to true forces a full copy, regardless of file matching.
        /// </summary>
        /// <param name="source">Source directory</param>
        /// <param name="destination">Destination directory</param>
        /// <param name="options">options</param>
        public static void Copy(string source, string destination, CopyFlags options)
        {
            if (source == null && !Directory.Exists(source))
            {
                throw new ArgumentException("Invalid source path", source);
            }

            if (destination == null)
            {
                throw new ArgumentNullException(destination, "Null destination path");
            }

            // Copying onto yourself does nothing
            if (source.Equals(destination, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            // Cleanup existing destination folder if clearDestination flag is set to true
            if (Directory.Exists(destination) && (options & CopyFlags.ClearDestinationDirectoryFirst) != 0)
            {
                DeleteDirectory(false, destination);
            }

            RobocopyUtilities.CopyDirectory(source, destination, (options & CopyFlags.DisableRecursive) != 0);
        }
Beispiel #2
0
 public void EmitBinOp(BinaryOperator binOp, MachineOperand dst, DataType dtDst, Expression left, Expression right, CopyFlags flags)
 {
     Constant c = right as Constant;
     if (c != null)
     {
         if (c.DataType == PrimitiveType.Byte && left.DataType != c.DataType)
         {
             right = emitter.Const(left.DataType, c.ToInt32());
         }
     }
     //EmitCopy(dst, new BinaryExpression(binOp, dtDst, left, right), true, emitCc);
     EmitCopy(dst, new BinaryExpression(binOp, dtDst, left, right), flags);
 }
Beispiel #3
0
 private void RewriteUnaryOperator(UnaryOperator op, MachineOperand opDst, MachineOperand opSrc, CopyFlags flags)
 {
     EmitCopy(opDst, new UnaryExpression(op, opSrc.Width, SrcOp(opSrc)), flags);
 }
Beispiel #4
0
        /// <summary>
        /// Performs a buffer to buffer, or buffer to texture copy.
        /// </summary>
        /// <param name="argument">Method call argument</param>
        private void LaunchDma(int argument)
        {
            var memoryManager = _channel.MemoryManager;

            CopyFlags copyFlags = (CopyFlags)argument;

            bool srcLinear = copyFlags.HasFlag(CopyFlags.SrcLinear);
            bool dstLinear = copyFlags.HasFlag(CopyFlags.DstLinear);
            bool copy2D    = copyFlags.HasFlag(CopyFlags.MultiLineEnable);
            bool remap     = copyFlags.HasFlag(CopyFlags.RemapEnable);

            uint size = _state.State.LineLengthIn;

            if (size == 0)
            {
                return;
            }

            ulong srcGpuVa = ((ulong)_state.State.OffsetInUpperUpper << 32) | _state.State.OffsetInLower;
            ulong dstGpuVa = ((ulong)_state.State.OffsetOutUpperUpper << 32) | _state.State.OffsetOutLower;

            int xCount = (int)_state.State.LineLengthIn;
            int yCount = (int)_state.State.LineCount;

            _3dEngine.FlushUboDirty();

            if (copy2D)
            {
                // Buffer to texture copy.
                int componentSize = (int)_state.State.SetRemapComponentsComponentSize + 1;
                int srcBpp        = remap ? ((int)_state.State.SetRemapComponentsNumSrcComponents + 1) * componentSize : 1;
                int dstBpp        = remap ? ((int)_state.State.SetRemapComponentsNumDstComponents + 1) * componentSize : 1;

                var dst = Unsafe.As <uint, DmaTexture>(ref _state.State.SetDstBlockSize);
                var src = Unsafe.As <uint, DmaTexture>(ref _state.State.SetSrcBlockSize);

                int srcStride = (int)_state.State.PitchIn;
                int dstStride = (int)_state.State.PitchOut;

                var srcCalculator = new OffsetCalculator(
                    src.Width,
                    src.Height,
                    srcStride,
                    srcLinear,
                    src.MemoryLayout.UnpackGobBlocksInY(),
                    src.MemoryLayout.UnpackGobBlocksInZ(),
                    srcBpp);

                var dstCalculator = new OffsetCalculator(
                    dst.Width,
                    dst.Height,
                    dstStride,
                    dstLinear,
                    dst.MemoryLayout.UnpackGobBlocksInY(),
                    dst.MemoryLayout.UnpackGobBlocksInZ(),
                    dstBpp);

                (int srcBaseOffset, int srcSize) = srcCalculator.GetRectangleRange(src.RegionX, src.RegionY, xCount, yCount);
                (int dstBaseOffset, int dstSize) = dstCalculator.GetRectangleRange(dst.RegionX, dst.RegionY, xCount, yCount);

                if (srcLinear && srcStride < 0)
                {
                    srcBaseOffset += srcStride * (yCount - 1);
                }

                if (dstLinear && dstStride < 0)
                {
                    dstBaseOffset += dstStride * (yCount - 1);
                }

                ReadOnlySpan <byte> srcSpan = memoryManager.GetSpan(srcGpuVa + (ulong)srcBaseOffset, srcSize, true);
                Span <byte>         dstSpan = memoryManager.GetSpan(dstGpuVa + (ulong)dstBaseOffset, dstSize).ToArray();

                bool completeSource = IsTextureCopyComplete(src, srcLinear, srcBpp, srcStride, xCount, yCount);
                bool completeDest   = IsTextureCopyComplete(dst, dstLinear, dstBpp, dstStride, xCount, yCount);

                if (completeSource && completeDest)
                {
                    var target = memoryManager.Physical.TextureCache.FindTexture(
                        memoryManager,
                        dst,
                        dstGpuVa,
                        dstBpp,
                        dstStride,
                        xCount,
                        yCount,
                        dstLinear);

                    if (target != null)
                    {
                        ReadOnlySpan <byte> data;
                        if (srcLinear)
                        {
                            data = LayoutConverter.ConvertLinearStridedToLinear(
                                target.Info.Width,
                                target.Info.Height,
                                1,
                                1,
                                srcStride,
                                target.Info.FormatInfo.BytesPerPixel,
                                srcSpan);
                        }
                        else
                        {
                            data = LayoutConverter.ConvertBlockLinearToLinear(
                                src.Width,
                                src.Height,
                                1,
                                target.Info.Levels,
                                1,
                                1,
                                1,
                                srcBpp,
                                src.MemoryLayout.UnpackGobBlocksInY(),
                                src.MemoryLayout.UnpackGobBlocksInZ(),
                                1,
                                new SizeInfo((int)target.Size),
                                srcSpan);
                        }

                        target.SetData(data);
                        target.SignalModified();

                        return;
                    }
                    else if (srcCalculator.LayoutMatches(dstCalculator))
                    {
                        srcSpan.CopyTo(dstSpan); // No layout conversion has to be performed, just copy the data entirely.

                        memoryManager.Write(dstGpuVa + (ulong)dstBaseOffset, dstSpan);

                        return;
                    }
                }

                unsafe bool Convert <T>(Span <byte> dstSpan, ReadOnlySpan <byte> srcSpan) where T : unmanaged
                {
                    fixed(byte *dstPtr = dstSpan, srcPtr = srcSpan)
                    {
                        byte *dstBase = dstPtr - dstBaseOffset; // Layout offset is relative to the base, so we need to subtract the span's offset.
                        byte *srcBase = srcPtr - srcBaseOffset;

                        for (int y = 0; y < yCount; y++)
                        {
                            srcCalculator.SetY(src.RegionY + y);
                            dstCalculator.SetY(dst.RegionY + y);

                            for (int x = 0; x < xCount; x++)
                            {
                                int srcOffset = srcCalculator.GetOffset(src.RegionX + x);
                                int dstOffset = dstCalculator.GetOffset(dst.RegionX + x);

                                *(T *)(dstBase + dstOffset) = *(T *)(srcBase + srcOffset);
                            }
                        }
                    }

                    return(true);
                }

                bool _ = srcBpp switch
                {
                    1 => Convert <byte>(dstSpan, srcSpan),
                    2 => Convert <ushort>(dstSpan, srcSpan),
                    4 => Convert <uint>(dstSpan, srcSpan),
                    8 => Convert <ulong>(dstSpan, srcSpan),
                    12 => Convert <Bpp12Pixel>(dstSpan, srcSpan),
                    16 => Convert <Vector128 <byte> >(dstSpan, srcSpan),
                    _ => throw new NotSupportedException($"Unable to copy ${srcBpp} bpp pixel format.")
                };

                memoryManager.Write(dstGpuVa + (ulong)dstBaseOffset, dstSpan);
            }
            else
            {
                if (remap &&
                    _state.State.SetRemapComponentsDstX == SetRemapComponentsDst.ConstA &&
                    _state.State.SetRemapComponentsDstY == SetRemapComponentsDst.ConstA &&
                    _state.State.SetRemapComponentsDstZ == SetRemapComponentsDst.ConstA &&
                    _state.State.SetRemapComponentsDstW == SetRemapComponentsDst.ConstA &&
                    _state.State.SetRemapComponentsNumSrcComponents == SetRemapComponentsNumComponents.One &&
                    _state.State.SetRemapComponentsNumDstComponents == SetRemapComponentsNumComponents.One &&
                    _state.State.SetRemapComponentsComponentSize == SetRemapComponentsComponentSize.Four)
                {
                    // Fast path for clears when remap is enabled.
                    memoryManager.Physical.BufferCache.ClearBuffer(memoryManager, dstGpuVa, size * 4, _state.State.SetRemapConstA);
                }
                else
                {
                    // TODO: Implement remap functionality.
                    // Buffer to buffer copy.
                    memoryManager.Physical.BufferCache.CopyBuffer(memoryManager, srcGpuVa, dstGpuVa, size);
                }
            }
        }
Beispiel #5
0
 private void RewriteUnaryOperator(Func <Expression, Expression> op, MachineOperand opDst, MachineOperand opSrc, CopyFlags flags)
 {
     EmitCopy(opDst, op(SrcOp(opSrc)), flags);
 }
        /// <summary>
        /// This method is used to copy or move one or more properties from one object to another. 
        /// </summary>
        /// <param name="copyFlag">Specifies the CopyFlags in the call request.</param>
        /// <param name="isWantAsynchronousZero">Indicates whether WantAsynchronous parameter in call request is zero.</param>
        /// <param name="isDestinationExist">Indicates whether destination object is exist for [RopCopyProperties]</param>
        /// <param name="isPropertiesDeleted">If CopyFlags is set to Move,Source object will be deleted after copy to.</param>
        /// <param name="isChangedInDB">Indicates whether the change is submit to DB.</param>
        /// <param name="isOverwriteDestination">If CopyFlags is set to NoOverWrite,Destination should not be overwritten.</param>
        /// <param name="isReturnedRopProgress">If this ROP is performed Asynchronously,RopProgress response returned 
        /// instead of RopCopyProperties response.</param>
        /// <param name="error">If destination object is not exist,NullDestinationObject error will be returned.</param>
        public void RopCopyPropertiesMethod(
            CopyFlags copyFlag,
            bool isWantAsynchronousZero,
            bool isDestinationExist,
            out bool isPropertiesDeleted,
            out bool isChangedInDB,
            out bool isOverwriteDestination,
            out bool isReturnedRopProgress,
            out CPRPTErrorCode error)
        {
            // Check if there are conflict SHOULD/MAY settings 
            this.CheckRequirementConflict(86701, 86502);
            this.CheckRequirementConflict(86704, 50101);
            this.CheckRequirementConflict(86705, 88001);

            #region Set parameter
            isPropertiesDeleted = false;
            isChangedInDB = false;
            isOverwriteDestination = false;
            isReturnedRopProgress = false;
            error = CPRPTErrorCode.None;

            byte copyFlags = (byte)RopCopyPropertiesCopyFlags.None;
            switch (copyFlag)
            {
                case CopyFlags.None:
                    copyFlags = (byte)RopCopyPropertiesCopyFlags.None;
                    break;
                case CopyFlags.Move:
                    copyFlags = (byte)RopCopyPropertiesCopyFlags.Move;
                    break;
                case CopyFlags.NoOverWriteAndDestPropNull:
                    copyFlags = (byte)RopCopyPropertiesCopyFlags.NoOverwrite;
                    break;
                case CopyFlags.NoOverWrite:
                    copyFlags = (byte)RopCopyPropertiesCopyFlags.NoOverwrite;
                    break;
                case CopyFlags.MoveAndNoOverWrite:
                    copyFlags = (byte)RopCopyPropertiesCopyFlags.MoveAndOverwrite;
                    break;
                case CopyFlags.Other:
                    copyFlags = (byte)4;
                    break;
                default:
                    this.Site.Assert.Fail("Invalid RopCopyPropertiesCopyFlags enum vaule {0}", copyFlag);
                    break;
            }

            byte wantAsynchronous = 0;
            if (!isWantAsynchronousZero)
            {
                wantAsynchronous = 1;
            }

            uint sourceHandle = this.cprptSecondHandle;
            uint destHandle = InvalidHandle;
            #endregion

            #region Set source and destination handle property
            TaggedPropertyValue[] sourceTag = new TaggedPropertyValue[1];
            sourceTag[0] = this.GetTaggedPropertyTag(ObjectToOperate.FirstObject);
            sourceTag[0].Value = Common.AddInt16LengthBeforeBinaryArray(sourceTag[0].Value);

            TaggedPropertyValue[] destTag = new TaggedPropertyValue[1];
            destTag[0] = this.GetTaggedPropertyTag(ObjectToOperate.FirstObject);
            destTag[0].Value = Common.AddInt16LengthBeforeBinaryArray(destTag[0].Value);
            destTag[0].Value[2]++;

            if (isDestinationExist)
            {
                destHandle = this.cprptFirstHandle;
                if (this.cprptCurrentType == ServerObjectType.Folder)
                {
                    RopCreateFolderResponse createFolderResponse;
                    string displayName = SubFolder;
                    sourceHandle = this.RopCreateFolder(sourceHandle, out createFolderResponse, displayName, "Comment: " + displayName, true);
                }

                this.RopSetProperties(destHandle, destTag, true);
                if (this.cprptCurrentType == ServerObjectType.Message)
                {
                    this.RopSaveChangesMessage(destHandle, true);
                }
                else if (this.cprptCurrentType == ServerObjectType.Attachment)
                {
                    this.RopSaveChangesAttachment(destHandle, true);
                    this.RopSaveChangesMessage(cprptMessageHandle[0], true);
                }

                #region Store destHandle property
                // Search property value for the first object
                TaggedPropertyValue tag = new TaggedPropertyValue
                {
                    PropertyTag = destTag[0].PropertyTag
                };
                RopGetPropertiesSpecificResponse destTagValue = this.RopGetPropertiesSpecific(destHandle, ConstValues.PropertySizeLimitNone, ConstValues.WantUnicodeNo, new PropertyTag[] { tag.PropertyTag });
                tag.Value = destTagValue.RowData.PropertyValues[0].Value;

                // Store the TaggedPropertyValue for further verification
                this.tagPropertyValuesToVerification.Clear();
                switch (this.cprptCurrentType)
                {
                    case ServerObjectType.Folder:
                        this.tagPropertyValuesToVerification.Add(ConstValues.ServerObjectTypeFolderKey, tag);
                        break;
                    case ServerObjectType.Message:
                        this.tagPropertyValuesToVerification.Add(ConstValues.ServerObjectTypeMessageKey, tag);
                        break;
                    case ServerObjectType.Attachment:
                        this.tagPropertyValuesToVerification.Add(ConstValues.ServerObjectTypeAttachmentKey, tag);
                        break;
                    default:
                        break;
                }
                #endregion
            }

            this.RopSetProperties(sourceHandle, sourceTag, true);
            if (this.cprptCurrentType == ServerObjectType.Message)
            {
                this.RopSaveChangesMessage(sourceHandle, true);
            }
            else if (this.cprptCurrentType == ServerObjectType.Attachment)
            {
                this.RopSaveChangesAttachment(sourceHandle, true);
                this.RopSaveChangesMessage(cprptMessageHandle[0], true);
            }
            #endregion

            // Add sourceTags[1] to verify PropertyProblems structure
            PropertyTag[] sourceTags = new PropertyTag[2];
            sourceTags[0] = sourceTag[0].PropertyTag;
            sourceTags[1] = sourceTag[0].PropertyTag;
            sourceTags[1].PropertyId--;

            object responseObj = this.RopCopyProperties(sourceHandle, destHandle, (byte)HandleIndex.FirstIndex, (byte)HandleIndex.SecondIndex, wantAsynchronous, copyFlags, sourceTags);

            if (responseObj is RopProgressResponse)
            {
                isReturnedRopProgress = true;
            }
            else
            {
                RopCopyPropertiesResponse copyPropertiesResponse = (RopCopyPropertiesResponse)responseObj;

                if (copyPropertiesResponse.ReturnValue != (uint)CPRPTErrorCode.None)
                {
                    #region Return error
                    switch ((CPRPTErrorCode)copyPropertiesResponse.ReturnValue)
                    {
                        case CPRPTErrorCode.NullDestinationObject:
                            error = CPRPTErrorCode.NullDestinationObject;
                            break;
                        case CPRPTErrorCode.NotSupported:
                            error = CPRPTErrorCode.NotSupported;
                            break;
                        case CPRPTErrorCode.InvalidParameter:
                            error = CPRPTErrorCode.InvalidParameter;
                            break;
                        default:
                            error = CPRPTErrorCode.Other;
                            break;
                    }
                    #endregion

                    this.VerifyRopCopyProperties(copyPropertiesResponse, this.cprptCurrentType, copyFlag, false);
                }
                else
                {
                    #region Check if the property is changed in DB
                    string objKey;
                    switch (this.cprptCurrentType)
                    {
                        case ServerObjectType.Folder:
                            objKey = ConstValues.ServerObjectTypeFolderKey;
                            break;
                        case ServerObjectType.Message:
                            objKey = ConstValues.ServerObjectTypeMessageKey;
                            break;
                        case ServerObjectType.Attachment:
                            objKey = ConstValues.ServerObjectTypeAttachmentKey;
                            break;
                        default:
                            objKey = string.Empty;
                            break;
                    }

                    bool isPropertyFound;
                    byte[] propertyValueBeforeSave = this.Session2GetPropertyData(objKey, destTag[0].PropertyTag, out isPropertyFound);

                    isChangedInDB = !Common.CompareByteArray(propertyValueBeforeSave, this.tagPropertyValuesToVerification[objKey].Value);
                    #endregion

                    this.VerifyRopCopyProperties(copyPropertiesResponse, this.cprptCurrentType, copyFlag, isPropertyFound);

                    #region Check if property is overwritten
                    if (isDestinationExist)
                    {
                        RopGetPropertiesSpecificResponse overWriteRes = this.RopGetPropertiesSpecific(destHandle, ConstValues.PropertySizeLimitNone, ConstValues.WantUnicodeNo, new PropertyTag[] { destTag[0].PropertyTag });
                        isOverwriteDestination = Common.CompareByteArray(overWriteRes.RowData.PropertyValues[0].Value, sourceTag[0].Value);
                    }
                    #endregion

                    #region Check if property is deleted
                    // The message and attachment objects must apply the changes to database
                    if (this.cprptCurrentType == ServerObjectType.Message)
                    {
                        this.RopSaveChangesMessage(sourceHandle, true);
                    }
                    else if (this.cprptCurrentType == ServerObjectType.Attachment)
                    {
                        this.RopSaveChangesAttachment(sourceHandle, true);
                        this.RopSaveChangesMessage(cprptMessageHandle[1], true);
                    }

                    switch (this.cprptCurrentType)
                    {
                        case ServerObjectType.Folder:
                            objKey = "Folder2";
                            break;
                        case ServerObjectType.Message:
                            objKey = "Message2";
                            break;
                        case ServerObjectType.Attachment:
                            objKey = "Attachment2";
                            break;
                        default:
                            objKey = string.Empty;
                            break;
                    }

                    if (this.cprptCurrentType == ServerObjectType.Folder)
                    {
                        RopGetPropertiesSpecificResponse tagValueRes = this.RopGetPropertiesSpecific(sourceHandle, ConstValues.PropertySizeLimitNone, ConstValues.WantUnicodeNo, new PropertyTag[] { sourceTag[0].PropertyTag });
                        if (tagValueRes.RowData.PropertyValues[0].Value == null)
                        {
                            isPropertiesDeleted = true;
                        }
                        else
                        {
                            byte[] expectedNotFoundError = new byte[] { 0x0f, 0x01, 0x04, 0x80 };
                            isPropertiesDeleted = Common.CompareByteArray(expectedNotFoundError, tagValueRes.RowData.PropertyValues[0].Value);
                        }
                    }
                    else
                    {
                        if (this.cprptCurrentType == ServerObjectType.Attachment && copyFlag == CopyFlags.Move && Common.IsRequirementEnabled(86704, this.Site))
                        {
                            isPropertiesDeleted = true;
                        }
                        else
                        {
                            byte[] propertyValueNow = this.Session2GetPropertyData(objKey, sourceTag[0].PropertyTag, out isPropertyFound);
                            if (!isPropertyFound)
                            {
                                isPropertiesDeleted = true;
                            }
                            else
                            {
                                byte[] expectedNotFoundError = new byte[] { 0x0f, 0x01, 0x04, 0x80 };
                                isPropertiesDeleted = Common.CompareByteArray(expectedNotFoundError, propertyValueNow);
                            }
                        }
                    }
                    #endregion
                }
            }
        }
Beispiel #7
0
 public virtual Task <FileSystemExitCode> PutFileAsync(string localName, RemotePath remoteName, CopyFlags copyFlags, Action <int> setProgress, CancellationToken token)
 {
     return(Task.FromResult(FileSystemExitCode.NotSupported));
 }
Beispiel #8
0
        internal string Parse()
        {
            Debugger.Instance.DebugMessage("Parsing CopyOptions...");
            var version = VersionManager.Version;
            var options = new StringBuilder();

            // Set Source, Destination and FileFilter
            options.Append($"\"{Source}\" ");
            options.Append($"\"{Destination}\" ");
            options.Append($"\"{FileFilter}\" ");
            Debugger.Instance.DebugMessage(string.Format("Parsing CopyOptions progress ({0}).", options.ToString()));

            #region Set Options
            var cleanedCopyFlags          = CopyFlags.CleanOptionInput();
            var cleanedDirectoryCopyFlags = DirectoryCopyFlags.CleanOptionInput();

            if (!string.IsNullOrWhiteSpace(cleanedCopyFlags))
            {
                options.Append(string.Format(COPY_FLAGS, cleanedCopyFlags));
                Debugger.Instance.DebugMessage(string.Format("Parsing CopyOptions progress ({0}).", options.ToString()));
            }
            if (!string.IsNullOrWhiteSpace(cleanedDirectoryCopyFlags))
            {
                options.Append(string.Format(DIRECTORY_COPY_FLAGS, cleanedDirectoryCopyFlags));
                Debugger.Instance.DebugMessage(string.Format("Parsing CopyOptions progress ({0}).", options.ToString()));
            }
            if (CopySubdirectories)
            {
                options.Append(COPY_SUBDIRECTORIES);
                Debugger.Instance.DebugMessage(string.Format("Parsing CopyOptions progress ({0}).", options.ToString()));
            }
            if (CopySubdirectoriesIncludingEmpty)
            {
                options.Append(COPY_SUBDIRECTORIES_INCLUDING_EMPTY);
            }
            if (Depth > 0)
            {
                options.Append(string.Format(DEPTH, Depth));
            }
            if (EnableRestartMode)
            {
                options.Append(ENABLE_RESTART_MODE);
            }
            if (EnableBackupMode)
            {
                options.Append(ENABLE_BACKUP_MODE);
            }
            if (EnableRestartModeWithBackupFallback)
            {
                options.Append(ENABLE_RESTART_MODE_WITH_BACKUP_FALLBACK);
            }
            if (UseUnbufferedIo && version >= 6.2)
            {
                options.Append(USE_UNBUFFERED_IO);
            }
            if (EnableEfsRawMode)
            {
                options.Append(ENABLE_EFSRAW_MODE);
            }
            if (CopyFilesWithSecurity)
            {
                options.Append(COPY_FILES_WITH_SECURITY);
            }
            if (CopyAll)
            {
                options.Append(COPY_ALL);
            }
            if (RemoveFileInformation)
            {
                options.Append(REMOVE_FILE_INFORMATION);
            }
            if (FixFileSecurityOnAllFiles)
            {
                options.Append(FIX_FILE_SECURITY_ON_ALL_FILES);
            }
            if (FixFileTimesOnAllFiles)
            {
                options.Append(FIX_FILE_TIMES_ON_ALL_FILES);
            }
            if (Purge)
            {
                options.Append(PURGE);
            }
            if (Mirror)
            {
                options.Append(MIRROR);
            }
            if (MoveFiles)
            {
                options.Append(MOVE_FILES);
            }
            if (MoveFilesAndDirectories)
            {
                options.Append(MOVE_FILES_AND_DIRECTORIES);
            }
            if (!string.IsNullOrWhiteSpace(AddAttributes))
            {
                options.Append(string.Format(ADD_ATTRIBUTES, AddAttributes.CleanOptionInput()));
            }
            if (!string.IsNullOrWhiteSpace(RemoveAttributes))
            {
                options.Append(string.Format(REMOVE_ATTRIBUTES, RemoveAttributes.CleanOptionInput()));
            }
            if (CreateDirectoryAndFileTree)
            {
                options.Append(CREATE_DIRECTORY_AND_FILE_TREE);
            }
            if (FatFiles)
            {
                options.Append(FAT_FILES);
            }
            if (TurnLongPathSupportOff)
            {
                options.Append(TURN_LONG_PATH_SUPPORT_OFF);
            }
            if (MonitorSourceChangesLimit > 0)
            {
                options.Append(string.Format(MONITOR_SOURCE_CHANGES_LIMIT, MonitorSourceChangesLimit));
            }
            if (MonitorSourceTimeLimit > 0)
            {
                options.Append(string.Format(MONITOR_SOURCE_TIME_LIMIT, MonitorSourceTimeLimit));
            }
            if (!string.IsNullOrWhiteSpace(RunHours))
            {
                options.Append(string.Format(RUN_HOURS, RunHours.CleanOptionInput()));
            }
            if (CheckPerFile)
            {
                options.Append(CHECK_PER_FILE);
            }
            if (InterPacketGap > 0)
            {
                options.Append(string.Format(INTER_PACKET_GAP, InterPacketGap));
            }
            if (CopySymbolicLink)
            {
                options.Append(COPY_SYMBOLIC_LINK);
            }
            if (MultiThreadedCopiesCount > 0)
            {
                options.Append(string.Format(MULTITHREADED_COPIES_COUNT, MultiThreadedCopiesCount));
            }
            if (DoNotCopyDirectoryInfo && version >= 6.2)
            {
                options.Append(DO_NOT_COPY_DIRECTORY_INFO);
            }
            if (DoNotUseWindowsCopyOffload && version >= 6.2)
            {
                options.Append(DO_NOT_USE_WINDOWS_COPY_OFFLOAD);
            }
            #endregion Set Options

            var parsedOptions = options.ToString();
            Debugger.Instance.DebugMessage(string.Format("CopyOptions parsed ({0}).", parsedOptions));
            return(parsedOptions);
        }
 public override FileOperationResult FileGet(string remoteName, ref string localName, CopyFlags copyFlags, RemoteInfo ri)
 {
     Trace("FileGet(from = \"{0}\", to = \"{1}\", flags = {2})", remoteName, localName, copyFlags);
     return(ResolvePath(remoteName).Download(localName, copyFlags, ri));
 }
Beispiel #10
0
        public override FileOperationResult FileGet(string remoteName, ref string localName, CopyFlags copyFlags, RemoteInfo ri)
        {
            bool cancelled = !Progress.SetProgress(remoteName, localName, 0);

            if (cancelled)
            {
                return(FileOperationResult.UserAbort);
            }

            if (File.Exists(localName))
            {
                //First time? - show user a prompt.
                if (copyFlags == CopyFlags.None || copyFlags == CopyFlags.Move)
                {
                    return(FileOperationResult.Exists);
                }
            }

            var blobItem          = Root.Instance.GetItemByPath(remoteName);
            var cancellationToken = new CancellationTokenSource();
            var name = localName;

            Action <int> setProgress = progress =>
            {
                cancelled = !Progress.SetProgress(remoteName, name, progress);
                if (cancelled)
                {
                    cancellationToken.Cancel();
                }
            };

            try
            {
                blobItem.DownloadFile(remoteName, localName, copyFlags, cancellationToken.Token, setProgress);
            }
            catch (Exception ex)
            {
                if (!(ex.InnerException is OperationCanceledException))
                {
                    throw;
                }

                //remove half downloaded file
                if (File.Exists(localName))
                {
                    File.Delete(localName);
                }
                return(FileOperationResult.UserAbort);
            }

            if ((copyFlags & CopyFlags.Move) == CopyFlags.Move)
            {
                blobItem.Delete();                 //Remove original on Move operation
            }

            Progress.SetProgress(remoteName, localName, 100);
            return(FileOperationResult.OK);
        }
Beispiel #11
0
 private void RewriteUnaryOperator(Func<Expression,Expression> op, MachineOperand opDst, MachineOperand opSrc, CopyFlags flags)
 {
     EmitCopy(opDst, op(SrcOp(opSrc)), flags);
 }
Beispiel #12
0
 public virtual FileOperationResult Upload(string localName, CopyFlags copyFlags)
 {
     return(FileOperationResult.Default);
 }
Beispiel #13
0
 public virtual FileOperationResult Download(string localName, CopyFlags copyFlags, RemoteInfo info)
 {
     return(FileOperationResult.Default);
 }
Beispiel #14
0
        /// <summary>
        /// Performs a buffer to buffer, or buffer to texture copy.
        /// </summary>
        /// <param name="argument">The LaunchDma call argument</param>
        private void DmaCopy(int argument)
        {
            var memoryManager = _channel.MemoryManager;

            CopyFlags copyFlags = (CopyFlags)argument;

            bool srcLinear = copyFlags.HasFlag(CopyFlags.SrcLinear);
            bool dstLinear = copyFlags.HasFlag(CopyFlags.DstLinear);
            bool copy2D    = copyFlags.HasFlag(CopyFlags.MultiLineEnable);
            bool remap     = copyFlags.HasFlag(CopyFlags.RemapEnable);

            uint size = _state.State.LineLengthIn;

            if (size == 0)
            {
                return;
            }

            ulong srcGpuVa = ((ulong)_state.State.OffsetInUpperUpper << 32) | _state.State.OffsetInLower;
            ulong dstGpuVa = ((ulong)_state.State.OffsetOutUpperUpper << 32) | _state.State.OffsetOutLower;

            int xCount = (int)_state.State.LineLengthIn;
            int yCount = (int)_state.State.LineCount;

            _3dEngine.CreatePendingSyncs();
            _3dEngine.FlushUboDirty();

            if (copy2D)
            {
                // Buffer to texture copy.
                int componentSize = (int)_state.State.SetRemapComponentsComponentSize + 1;
                int srcBpp        = remap ? ((int)_state.State.SetRemapComponentsNumSrcComponents + 1) * componentSize : 1;
                int dstBpp        = remap ? ((int)_state.State.SetRemapComponentsNumDstComponents + 1) * componentSize : 1;

                var dst = Unsafe.As <uint, DmaTexture>(ref _state.State.SetDstBlockSize);
                var src = Unsafe.As <uint, DmaTexture>(ref _state.State.SetSrcBlockSize);

                int srcRegionX = 0, srcRegionY = 0, dstRegionX = 0, dstRegionY = 0;

                if (!srcLinear)
                {
                    srcRegionX = src.RegionX;
                    srcRegionY = src.RegionY;
                }

                if (!dstLinear)
                {
                    dstRegionX = dst.RegionX;
                    dstRegionY = dst.RegionY;
                }

                int srcStride = (int)_state.State.PitchIn;
                int dstStride = (int)_state.State.PitchOut;

                var srcCalculator = new OffsetCalculator(
                    src.Width,
                    src.Height,
                    srcStride,
                    srcLinear,
                    src.MemoryLayout.UnpackGobBlocksInY(),
                    src.MemoryLayout.UnpackGobBlocksInZ(),
                    srcBpp);

                var dstCalculator = new OffsetCalculator(
                    dst.Width,
                    dst.Height,
                    dstStride,
                    dstLinear,
                    dst.MemoryLayout.UnpackGobBlocksInY(),
                    dst.MemoryLayout.UnpackGobBlocksInZ(),
                    dstBpp);

                (int srcBaseOffset, int srcSize) = srcCalculator.GetRectangleRange(srcRegionX, srcRegionY, xCount, yCount);
                (int dstBaseOffset, int dstSize) = dstCalculator.GetRectangleRange(dstRegionX, dstRegionY, xCount, yCount);

                if (srcLinear && srcStride < 0)
                {
                    srcBaseOffset += srcStride * (yCount - 1);
                }

                if (dstLinear && dstStride < 0)
                {
                    dstBaseOffset += dstStride * (yCount - 1);
                }

                ReadOnlySpan <byte> srcSpan = memoryManager.GetSpan(srcGpuVa + (ulong)srcBaseOffset, srcSize, true);

                bool completeSource = IsTextureCopyComplete(src, srcLinear, srcBpp, srcStride, xCount, yCount);
                bool completeDest   = IsTextureCopyComplete(dst, dstLinear, dstBpp, dstStride, xCount, yCount);

                if (completeSource && completeDest)
                {
                    var target = memoryManager.Physical.TextureCache.FindTexture(
                        memoryManager,
                        dstGpuVa,
                        dstBpp,
                        dstStride,
                        dst.Height,
                        xCount,
                        yCount,
                        dstLinear,
                        dst.MemoryLayout.UnpackGobBlocksInY(),
                        dst.MemoryLayout.UnpackGobBlocksInZ());

                    if (target != null)
                    {
                        ReadOnlySpan <byte> data;
                        if (srcLinear)
                        {
                            data = LayoutConverter.ConvertLinearStridedToLinear(
                                target.Info.Width,
                                target.Info.Height,
                                1,
                                1,
                                xCount * srcBpp,
                                srcStride,
                                target.Info.FormatInfo.BytesPerPixel,
                                srcSpan);
                        }
                        else
                        {
                            data = LayoutConverter.ConvertBlockLinearToLinear(
                                src.Width,
                                src.Height,
                                src.Depth,
                                1,
                                1,
                                1,
                                1,
                                1,
                                srcBpp,
                                src.MemoryLayout.UnpackGobBlocksInY(),
                                src.MemoryLayout.UnpackGobBlocksInZ(),
                                1,
                                new SizeInfo((int)target.Size),
                                srcSpan);
                        }

                        target.SynchronizeMemory();
                        target.SetData(data);
                        target.SignalModified();
                        return;
                    }
                    else if (srcCalculator.LayoutMatches(dstCalculator))
                    {
                        // No layout conversion has to be performed, just copy the data entirely.
                        memoryManager.Write(dstGpuVa + (ulong)dstBaseOffset, srcSpan);
                        return;
                    }
                }

                unsafe bool Convert <T>(Span <byte> dstSpan, ReadOnlySpan <byte> srcSpan) where T : unmanaged
                {
                    if (srcLinear && dstLinear && srcBpp == dstBpp)
                    {
                        // Optimized path for purely linear copies - we don't need to calculate every single byte offset,
                        // and we can make use of Span.CopyTo which is very very fast (even compared to pointers)
                        for (int y = 0; y < yCount; y++)
                        {
                            srcCalculator.SetY(srcRegionY + y);
                            dstCalculator.SetY(dstRegionY + y);
                            int srcOffset = srcCalculator.GetOffset(srcRegionX);
                            int dstOffset = dstCalculator.GetOffset(dstRegionX);
                            srcSpan.Slice(srcOffset - srcBaseOffset, xCount * srcBpp)
                            .CopyTo(dstSpan.Slice(dstOffset - dstBaseOffset, xCount * dstBpp));
                        }
                    }
                    else
                    {
                        fixed(byte *dstPtr = dstSpan, srcPtr = srcSpan)
                        {
                            byte *dstBase = dstPtr - dstBaseOffset; // Layout offset is relative to the base, so we need to subtract the span's offset.
                            byte *srcBase = srcPtr - srcBaseOffset;

                            for (int y = 0; y < yCount; y++)
                            {
                                srcCalculator.SetY(srcRegionY + y);
                                dstCalculator.SetY(dstRegionY + y);

                                for (int x = 0; x < xCount; x++)
                                {
                                    int srcOffset = srcCalculator.GetOffset(srcRegionX + x);
                                    int dstOffset = dstCalculator.GetOffset(dstRegionX + x);

                                    *(T *)(dstBase + dstOffset) = *(T *)(srcBase + srcOffset);
                                }
                            }
                        }
                    }

                    return(true);
                }

                // OPT: This allocates a (potentially) huge temporary array and then copies an existing
                // region of memory into it, data that might get overwritten entirely anyways. Ideally this should
                // all be rewritten to use pooled arrays, but that gets complicated with packed data and strides
                Span <byte> dstSpan = memoryManager.GetSpan(dstGpuVa + (ulong)dstBaseOffset, dstSize).ToArray();

                bool _ = srcBpp switch
                {
                    1 => Convert <byte>(dstSpan, srcSpan),
                    2 => Convert <ushort>(dstSpan, srcSpan),
                    4 => Convert <uint>(dstSpan, srcSpan),
                    8 => Convert <ulong>(dstSpan, srcSpan),
                    12 => Convert <Bpp12Pixel>(dstSpan, srcSpan),
                    16 => Convert <Vector128 <byte> >(dstSpan, srcSpan),
                    _ => throw new NotSupportedException($"Unable to copy ${srcBpp} bpp pixel format.")
                };

                memoryManager.Write(dstGpuVa + (ulong)dstBaseOffset, dstSpan);
            }
            else
            {
                if (remap &&
                    _state.State.SetRemapComponentsDstX == SetRemapComponentsDst.ConstA &&
                    _state.State.SetRemapComponentsDstY == SetRemapComponentsDst.ConstA &&
                    _state.State.SetRemapComponentsDstZ == SetRemapComponentsDst.ConstA &&
                    _state.State.SetRemapComponentsDstW == SetRemapComponentsDst.ConstA &&
                    _state.State.SetRemapComponentsNumSrcComponents == SetRemapComponentsNumComponents.One &&
                    _state.State.SetRemapComponentsNumDstComponents == SetRemapComponentsNumComponents.One &&
                    _state.State.SetRemapComponentsComponentSize == SetRemapComponentsComponentSize.Four)
                {
                    // Fast path for clears when remap is enabled.
                    memoryManager.Physical.BufferCache.ClearBuffer(memoryManager, dstGpuVa, size * 4, _state.State.SetRemapConstA);
                }
                else
                {
                    // TODO: Implement remap functionality.
                    // Buffer to buffer copy.

                    bool srcIsPitchKind = memoryManager.GetKind(srcGpuVa).IsPitch();
                    bool dstIsPitchKind = memoryManager.GetKind(dstGpuVa).IsPitch();

                    if (!srcIsPitchKind && dstIsPitchKind)
                    {
                        CopyGobBlockLinearToLinear(memoryManager, srcGpuVa, dstGpuVa, size);
                    }
                    else if (srcIsPitchKind && !dstIsPitchKind)
                    {
                        CopyGobLinearToBlockLinear(memoryManager, srcGpuVa, dstGpuVa, size);
                    }
                    else
                    {
                        memoryManager.Physical.BufferCache.CopyBuffer(memoryManager, srcGpuVa, dstGpuVa, size);
                    }
                }
            }
        }
 public override FileOperationResult FilePut(string localName, ref string remoteName, CopyFlags copyFlags)
 {
     Trace("FilePut(from = \"{0}\", to = \"{1}\", flags = {2})", localName, remoteName, copyFlags);
     return(ResolvePath(remoteName).Upload(localName, copyFlags));
 }
Beispiel #16
0
 public virtual FileSystemExitCode GetFile(string remoteName, ref string localName, CopyFlags copyFlags,
                                           RemoteInfo remoteInfo)
 {
     return(FileSystemExitCode.NotSupported);
 }
Beispiel #17
0
        public override FileOperationResult FilePut(string localName, ref string remoteName, CopyFlags copyFlags)
        {
            bool cancelled = !Progress.SetProgress(remoteName, localName, 0);

            if (cancelled)
            {
                return(FileOperationResult.UserAbort);
            }

            FileSystemItemBase remoteBlob = null;

            if (Root.Instance.TryGetItemByPath(remoteName, out remoteBlob))
            {
                //First time? - show user a prompt.
                if ((copyFlags & CopyFlags.Overwrite) != CopyFlags.Overwrite)
                {
                    return(FileOperationResult.Exists);
                }
            }

            int    lastSlashIndex     = remoteName.LastIndexOf('\\');
            string existingFolderPath = remoteName.Substring(0, lastSlashIndex);
            string newFolderName      = remoteName.Substring(lastSlashIndex + 1);

            var directory         = Root.Instance.GetItemByPath(existingFolderPath);
            var cancellationToken = new CancellationTokenSource();
            var name = remoteName;

            Action <int> setProgress = progress =>
            {
                cancelled = !Progress.SetProgress(localName, name, progress);
                if (cancelled)
                {
                    cancellationToken.Cancel();
                }
            };

            try
            {
                directory.UploadFile(localName, newFolderName, copyFlags, cancellationToken.Token, setProgress);
            }
            catch (OperationCanceledException ex)
            {
                //remove half uploaded file
                if (Root.Instance.TryGetItemByPath(remoteName, out remoteBlob))
                {
                    remoteBlob.Delete();
                }
                return(FileOperationResult.UserAbort);
            }

            if ((copyFlags & CopyFlags.Move) == CopyFlags.Move)
            {
                File.Delete(localName);
            }

            Progress.SetProgress(remoteName, localName, 100);
            return(FileOperationResult.OK);
        }
Beispiel #18
0
        public override FileSystemExitCode PutFile(string localName, ref string remoteName, CopyFlags copyFlags)
        {
            bool   overWrite = (CopyFlags.Overwrite & copyFlags) != 0;
            string rmtName   = remoteName.Substring(1);

            if (File.Exists(rmtName) & !overWrite)
            {
                return(FileSystemExitCode.FileExists);
            }
            try {
                if ((CopyFlags.Move & copyFlags) != 0)
                {
                    MoveFileOptions options =
                        (overWrite) ? MoveFileOptions.ReplaceExisting : MoveFileOptions.None;
                    FileRoutines.MoveFile(new FileInfo(localName), new FileInfo(rmtName), options, OnCopyFile);
                }
                else
                {
                    CopyFileOptions options =
                        (overWrite) ? CopyFileOptions.None : CopyFileOptions.FailIfDestinationExists;
                    FileRoutines.CopyFile(new FileInfo(localName), new FileInfo(rmtName), options, OnCopyFile);
                }
                TraceProc(TraceLevel.Warning, "Local file '" + localName + "' transferred!");
                return(FileSystemExitCode.OK);
            } catch (Exception ex) {
                MessageBox.Show(
                    "File operation error:" + Environment.NewLine + ex.Message,
                    "LFS Plugin (PutFile)", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(FileSystemExitCode.WriteError);
            }
        }
        public static void RopCopyToMethodCall(CopyFlags copyFlag, bool isWantAsynchronousZero, bool isWantSubObjectsZero, bool isDestinationExist)
        {
            Condition.IsTrue(isInitialized && isFirstObjectGot && isSecondObjectGot &&
                (globalObj == ServerObjectType.Message ||
                globalObj == ServerObjectType.Attachment ||
                globalObj == ServerObjectType.Folder));

            ModelHelper.CaptureRequirement(
                821,
                @"[In Processing RopCopyTo] The source object and destination object need to be of the same type, and MUST be a Message object, Folder object, or Attachment object.");

            clientCopyFlag = copyFlag;
            isClientWantAsynchronous = !isWantAsynchronousZero;
            isClientWantSubObjects = !isWantSubObjectsZero;
            isDestinationInRequestExist = isDestinationExist;
        }
        /// <summary>
        /// Verify the RopCopyProperties operation related requirements.
        /// </summary>
        /// <param name="ropCopyPropertiesResponse">The RopCopyProperties response buffer structure.</param>
        /// <param name="objectType">Indicates which object type the RopCopyProperties operation is acting on.</param>
        /// <param name="copyFlags">CopyFlags parameter in request of RopCopyProperties.</param>
        /// <param name="isPropertyFound">Indicates the property is found or not.</param>
        private void VerifyRopCopyProperties(
            RopCopyPropertiesResponse ropCopyPropertiesResponse,
            ServerObjectType objectType,
            CopyFlags copyFlags,
            bool isPropertyFound)
        {
            // Since the RopCopyProperties ROP response was parsed successfully, MS-OXCPRPT_R50003 can be captured directly.
            Site.CaptureRequirement(
                50003,
                @"[In Processing RopCopyProperties] The server responds with a RopCopyProperties ROP response buffer.");

            if (ropCopyPropertiesResponse.ReturnValue.Equals((uint)CPRPTErrorCode.None))
            {
                // The parser has ensured the field satisfied the format, otherwise the response cannot be received.
                Site.CaptureRequirement(
                  16801,
                  @"[In RopCopyProperties ROP Response Buffer] DestHandleIndex: 4 bytes integer.");

                if (objectType == ServerObjectType.Message)
                {
                    // If the object type this operation acting on is Message object and this operation is performed successfully, then the following requirement can be captured.
                    Site.CaptureRequirement(
                        14901,
                        @"[In RopCopyProperties ROP] This operation [RopCopyProperties ROP] is valid on Message objects.");
                }

                if (objectType == ServerObjectType.Folder)
                {
                    // If the object type this operation acting on is Folder object and this operation is performed successfully, then the following requirement can be captured.
                    Site.CaptureRequirement(
                        14902,
                        @"[In RopCopyProperties ROP] This operation [RopCopyProperties ROP] is valid on Folder objects.");
                }

                if (objectType == ServerObjectType.Attachment)
                {
                    // If the object type this operation acting on is Attachment object and this operation is performed successfully, then the following requirement can be captured.
                    Site.CaptureRequirement(
                        14903,
                        @"[In RopCopyProperties ROP] This operation [RopCopyProperties ROP] is valid on Attachment objects.");
                }

                // The parser has ensured the field satisfied the format, otherwise the response cannot be received.
                Site.CaptureRequirement(
                165,
                @"[In RopCopyProperties ROP Response Buffer] propertyProblemCount: 2 bytes integer.");

                Site.CaptureRequirementIfAreEqual<ushort>(
                      ropCopyPropertiesResponse.PropertyProblemCount,
                      (ushort)ropCopyPropertiesResponse.PropertyProblems.Length,
                      16502,
                      @"[In RopCopyProperties ROP Response Buffer] propertyProblemCount: An integer that specifies the number of elements contained in the PropertyProblems field. ");

                if (ropCopyPropertiesResponse.PropertyProblemCount != 0)
                {
                    // The parser has ensured the field satisfied the format, otherwise the response cannot be received.
                    Site.CaptureRequirement(
                        167,
                        @"[In RopCopyProperties ROP Response Buffer] PropertyProblems (variable): An array of PropertyProblem structures ([MS-OXCDATA] section 2.7).");

                    for (int counter = 0; counter < ropCopyPropertiesResponse.PropertyProblems.Length; counter++)
                    {
                        this.VerifyPropertyProblemSturctureInCDATA();
                    }
                }

                Site.CaptureRequirementIfIsTrue(
                   isPropertyFound,
                   500,
                   @"[In Processing RopCopyProperties] The server MUST copy or move the properties specified from the source object to the destination object.");
            }

            if (ropCopyPropertiesResponse.ReturnValue == 0x80070057)
            {
                // The parser has ensured the field satisfied the format, otherwise the response cannot be received.
                Site.CaptureRequirement(
                    "MS-OXCDATA",
                      904,
                     @"[In Error Codes] The numeric value (hex) for error code InvalidParameter is 0x80070057, %x57.00.07.80.");
            }

            if (ropCopyPropertiesResponse.ReturnValue == 0x80040102)
            {
                // The parser has ensured the field satisfied the format, otherwise the response cannot be received.
                Site.CaptureRequirement(
                    "MS-OXCDATA",
                      928,
                     @"[In Error Codes] The numeric value (hex) for error code NotSupported is 0x80040102, %x02.01.04.80.");
            }

            if (ropCopyPropertiesResponse.ReturnValue.Equals((uint)CPRPTErrorCode.NullDestinationObject))
            {
                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCPRPT_R168");

                // Verify MS-OXCPRPT requirement: MS-OXCPRPT_R168
                // The value of DestHandleIndex is not 0 means this field is present.
                Site.CaptureRequirementIfAreNotEqual<uint>(
                    0,
                    ropCopyPropertiesResponse.DestHandleIndex,
                    168,
                    @"[In RopCopyProperties ROP Response Buffer] DestHandleIndex: The DestHandleIndex field MUST be set to the value of the DestHandleIndex field of the ROP request buffer. ");

                // Verify MS-OXCPRPT requirement: MS-OXCPRPT_R737
                // The value of PropertyProblemCount is 0 means this field is not present.
                Site.CaptureRequirementIfAreEqual<ushort>(
                    0,
                    ropCopyPropertiesResponse.PropertyProblemCount,
                    737,
                    @"[In RopCopyProperties ROP Response Buffer] PropertyProblemCount: This field MUST NOT be present if the ReturnValue field is set to NullDestinationObject (0x00000503).");

                // Verify MS-OXCPRPT requirement: MS-OXCPRPT_R738
                // PropertyProblems is null means this field is not present.
                Site.CaptureRequirementIfIsNull(
                    ropCopyPropertiesResponse.PropertyProblems,
                    738,
                    @"[In RopCopyProperties ROP Response Buffer] propertyProblems: This field MUST NOT be present if the ReturnValue field is set to NullDestinationObject (0x00000503).");
            }
            else
            {
                // Verify MS-OXCPRPT requirement: MS-OXCPRPT_R170
                // The value of DestHandleIndex is 0 means this field is not present.
                Site.CaptureRequirementIfAreEqual<uint>(
                    0,
                    ropCopyPropertiesResponse.DestHandleIndex,
                    170,
                    @"[In RopCopyProperties ROP Response Buffer] DestHandleIndex: The DestHandleIndex field MUST NOT be present if the ReturnValue field is set to any value other than NullDestinationObject (0x00000503).");
            }

            if ((objectType == ServerObjectType.Folder) && (copyFlags == CopyFlags.Move))
            {
                if (Common.IsRequirementEnabled(882, this.Site))
                {
                    Site.CaptureRequirementIfAreEqual<uint>(
                        (uint)CPRPTErrorCode.NotSupported,
                        ropCopyPropertiesResponse.ReturnValue,
                        882,
                        @"[In Processing RopCopyProperties] Implementation does return NotSupported error, if the original object is a Folder object and the CopyFlags field has the Move flag set.(Microsoft Exchange Server 2007 and above follow this behavior)");
                }
            }
        }
Beispiel #21
0
        public virtual FileSystemExitCode PutFile(string localName, RemotePath remoteName, CopyFlags copyFlags)
        {
            try {
                // My ThreadKeeper class is needed here because calls to ProgressProc must be made from this thread and not from some random async one.
                using (var exec = new ThreadKeeper()) {
                    void Progress(int percentDone)
                    {
                        exec.RunInMainThread(() => {
                            if (ProgressProc(localName, remoteName, percentDone))
                            {
                                exec.Cancel();
                            }
                        });
                    }

                    var ret = exec.ExecAsync(asyncFunc: (token) => PutFileAsync(localName, remoteName, copyFlags, Progress, token));

                    return(ret);
                }
            }
            catch (TaskCanceledException) {
                return(FileSystemExitCode.UserAbort);
            }
            catch (OperationCanceledException) {
                return(FileSystemExitCode.UserAbort);
            }
            catch (AggregateException e) {
                if (HasCanceledException(e))
                {
                    return(FileSystemExitCode.UserAbort);
                }

                throw;
            }
        }
        /// <summary>
        /// Verify the RopCopyTo operation related requirements.
        /// </summary>
        /// <param name="ropCopyToResponse">The RopCopyTo response buffer structure.</param>
        /// <param name="copyToCondition">The condition to generate the corresponding error codes.</param>
        /// <param name="objectType">Indicates which object type the RopCopyProperties operation is acting on.</param>
        /// <param name="copyFlags">Indicates the copy flags.</param>
        private void VerifyRopCopyTo(RopCopyToResponse ropCopyToResponse, CopyToCondition copyToCondition, ServerObjectType objectType, CopyFlags copyFlags)
        {
            // Since the RopCopyTo ROP response was parsed successfully, MS-OXCPRPT_R50702 can be captured directly.
            Site.CaptureRequirement(
                50702,
                @"[In Processing RopCopyTo] The server responds with a RopCopyTo ROP response buffer.");

            if (ropCopyToResponse.ReturnValue == (uint)CPRPTErrorCode.NotSupported)
            {
                // The parser has ensured the field satisfied the format, otherwise the response cannot be received.
                Site.CaptureRequirement(
                    "MS-OXCDATA",
                     928,
                     @"[In Error Codes] The numeric value (hex) for error code NotSupported is 0x80040102, %x02.01.04.80.");
            }

            if (ropCopyToResponse.ReturnValue == (uint)CPRPTErrorCode.None)
            {
                if (objectType == ServerObjectType.Message)
                {
                    // If the object type this operation acting on is Message object and this operation is performed successfully, then the following requirement can be captured.
                    Site.CaptureRequirement(
                        17201,
                        @"[In RopCopyTo ROP] This operation [RopCopyTo ROP] is valid on Message objects.");
                }

                if (objectType == ServerObjectType.Folder)
                {
                    if (copyFlags == CopyFlags.Move)
                    {
                        if (Common.IsRequirementEnabled(5070511, this.Site))
                        {
                            // If the implementation return a successful response, it means it doesn't return NotSupported error. So it can be capture directly.
                            Site.CaptureRequirement(
                                5070511,
                                @"[In Processing RopCopyTo] Implementation does not return a NotSupported error (0x80040102), if the original object is a Folder object and the CopyFlags field has the Move flag set. (Microsoft Exchange Server 2007 and above follow this behavior.)");
                        }
                    }

                    // If the object type this operation acting on is Folder object and this operation is performed successfully, then the following requirement can be captured.
                    Site.CaptureRequirement(
                        17203,
                        @"[In RopCopyTo ROP] This operation [RopCopyTo ROP] is valid on Folder objects.");
                }

                if (objectType == ServerObjectType.Attachment)
                {
                    // If the object type this operation acting on is Attachment object and this operation is performed successfully, then the following requirement can be captured.
                    Site.CaptureRequirement(
                        17202,
                        @"[In RopCopyTo ROP] This operation [RopCopyTo ROP] is valid on Attachment objects.");
                }

                // The parser has ensured the field satisfied the format, otherwise the response cannot be received.
                Site.CaptureRequirement(
                   192,
                   @"[In RopCopyTo ROP Response Buffer] propertyProblemCount: 2 bytes integer.");

                if (ropCopyToResponse.PropertyProblemCount != 0)
                {
                    for (int counter = 0; counter < ropCopyToResponse.PropertyProblems.Length; counter++) 
                    {
                        this.VerifyPropertyProblemSturctureInCDATA();
                    }

                    Site.CaptureRequirementIfAreEqual<ushort>(
                        ropCopyToResponse.PropertyProblemCount,
                        (ushort)ropCopyToResponse.PropertyProblems.Length,
                        19201,
                        @"[In RopCopyTo ROP Response Buffer] propertyProblemCount: An integer that specifies the number of elements contained in the PropertyProblems field. ");

                    // The parser has ensured the field satisfied the format, otherwise the response cannot be received.
                    Site.CaptureRequirement(
                        193,
                        @"[In RopCopyTo ROP Response Buffer] propertyProblems (variable): An array of PropertyProblem structures ([MS-OXCDATA] section 2.7).");
                }

                // The parser has ensured the field satisfied the format, otherwise the response cannot be received.
                Site.CaptureRequirement(
                    19601,
                    @"[In RopCopyTo ROP Response Buffer] DestHandleIndex (4 bytes):  An integer.");
            }

            if (ropCopyToResponse.ReturnValue.Equals((uint)CPRPTErrorCode.NullDestinationObject))
            {
                // Verify MS-OXCPRPT requirement: MS-OXCPRPT_R195
                // The value of DestHandleIndex is not 0 means this field is present.
                Site.CaptureRequirementIfAreEqual<uint>(
                    1,
                    ropCopyToResponse.DestHandleIndex,
                    196,
                    @"[In RopCopyTo ROP Response Buffer] DestHandleIndex: The DestHandleIndex field MUST be set to the value of the DestHandleIndex field of the ROP request buffer");

                // Verify MS-OXCPRPT requirement: MS-OXCPRPT_R739
                // The value of PropertyProblemCount is 0 means this field is not present.
                Site.CaptureRequirementIfAreEqual<ushort>(
                    0,
                    ropCopyToResponse.PropertyProblemCount,
                    739,
                    @"[In RopCopyTo ROP Response Buffer] PropertyProblemCount: This field MUST NOT be present if the ReturnValue field is set to NullDestinationObject (0x00000503).");

                // Verify MS-OXCPRPT requirement: MS-OXCPRPT_R740
                // PropertyProblems is null means this field is not present.
                Site.CaptureRequirementIfIsNull(
                    ropCopyToResponse.PropertyProblems,
                    740,
                    @"[In RopCopyTo ROP Response Buffer] PropertyProblems: This field MUST NOT be present if the ReturnValue field is set to NullDestinationObject (0x00000503).");
            }
            else
            {
                // Verify MS-OXCPRPT requirement: MS-OXCPRPT_R197
                // The value of DestHandleIndex is 0 means this field is not present.
                Site.CaptureRequirementIfAreEqual<uint>(
                     0,
                     ropCopyToResponse.DestHandleIndex,
                    197,
                    @"[In RopCopyTo ROP Response Buffer] DestHandleIndex: The DestHandleIndex field MUST NOT be present if the ReturnValue field is set to any value other than NullDestinationObject (0x00000503).");
            }

            if (copyToCondition == CopyToCondition.SourceContainsDest)
            {
                if (objectType == ServerObjectType.Folder)
                {
                    if (Common.IsRequirementEnabled(89603, this.Site))
                    {
                        Site.CaptureRequirementIfAreEqual<uint>(
                            (uint)CPRPTErrorCode.FolderCycle,
                            ropCopyToResponse.ReturnValue,
                            89603,
                            @"[In Processing RopCopyTo] Implementation does return error code ""0x8004060B"" with name ""FolderCycle"" when The source folder contains the destination folder.(Microsoft Exchange Server 2007 and above follow this behavior)");
                    }
                }
            }
            else if (copyToCondition == CopyToCondition.SourceDestNotCompatible)
            {
                // CopyToCondition.SourceDestNotCompatible means source object and destination object are not compatible with each other for the copy operation.
                bool isR890Satisfied = ropCopyToResponse.ReturnValue == (uint)CPRPTErrorCode.NotSupported;

                if (Common.IsRequirementEnabled(890, this.Site))
                {
                    // Verify MS-OXCPRPT requirement: MS-OXCPRPT_R890
                    Site.CaptureRequirementIfIsTrue(
                        isR890Satisfied,
                        890,
                        @"[In Processing RopCopyTo] Implementation does return error code ""0x80040102"" with name ""NotSupported"",  when ""The source object and destination object are not compatible with each other for the copy operation."" (Microsoft Exchange Server 2007 and above follow this behavior)");

                    Site.CaptureRequirementIfIsTrue(
                        isR890Satisfied,
                        150,
                        @"[In RopCopyProperties ROP] Also, the source and destination object MUST be of the same type.");
                }
            }
            else if (copyToCondition == CopyToCondition.SourceDestHasSubObjWithSameDisplayName)
            {
                // CopyToCondition.SourceDestHasSubObjWithSameDisplayName means a sub-object cannot be copied because there is already a sub-object existing 
                // in the destination object with the same display name (PidTagDisplayName) as the sub-object to be copied.
                if (Common.IsRequirementEnabled(899, this.Site))
                {
                    // Add the debug information
                    Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCPRPT_R899, the return error code value is: {0}", ropCopyToResponse.ReturnValue);

                    // Verify MS-OXCPRPT requirement: MS-OXCPRPT_R899
                    Site.CaptureRequirementIfAreEqual<uint>(
                        (uint)CPRPTErrorCode.CollidingNames,
                        ropCopyToResponse.ReturnValue,
                        899,
                        @"[In Processing RopCopyTo] Implementation does return error code ""0x80040604"" with name ""CollidingNames"", when a subobject cannot be copied because there is already a subobject existing in the destination object with the same display name, which is specified in the PidTagDisplayName property ([MS-OXCFOLD] section 2.2.2.2.2.4), as the subobject to be copied.(Microsoft Exchange Server 2007 and above follow this behavior)");
                }
            }
            else if (copyToCondition == CopyToCondition.SourceMessageContainsDestMessage && Common.IsRequirementEnabled(89601, this.Site))
            {
                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCPRPT_R89601, the return error code value is: {0}", ropCopyToResponse.ReturnValue);

                // Verify MS-OXCPRPT requirement: MS-OXCPRPT_R89601
                Site.CaptureRequirementIfAreEqual<uint>(
                    (uint)CPRPTErrorCode.MessageCycle,
                    ropCopyToResponse.ReturnValue,
                    89601,
                    @"[In Appendix A: Product Behavior] Implementation does return error code ""0x00000504"" with name ""MessageCycle"" when the source message directly contains the destination message. (Exchange 2007 and above follow this behavior.)");
            }
            else if (copyToCondition == CopyToCondition.SourceMessageIndirectlyContainsDestMessage && Common.IsRequirementEnabled(89604, this.Site))
            {
                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCPRPT_R89604, the return error code value is: {0}", ropCopyToResponse.ReturnValue);

                // Verify MS-OXCPRPT requirement: MS-OXCPRPT_R89604
                Site.CaptureRequirementIfAreEqual<uint>(
                    (uint)CPRPTErrorCode.MessageCycle,
                    ropCopyToResponse.ReturnValue,
                    89604,
                    @"[In Appendix A: Product Behavior] Implementation does return error code ""0x00000504"" with name ""MessageCycle"" when the source message indirectly contains the destination message. (Exchange 2007 and above follow this behavior.)");            
            }
        }
Beispiel #23
0
        public void EmitBinOp(Func <Expression, Expression, Expression> binOp, MachineOperand dst, DataType dtDst, Expression left, Expression right, CopyFlags flags)
        {
            if (right is Constant c)
            {
                if (c.DataType.BitSize < left.DataType.BitSize)
                {
                    right = m.Const(left.DataType, c.ToInt64());
                }
            }
            var bin = binOp(left, right);

            bin.DataType = dtDst;
            EmitCopy(dst, bin, flags);
        }
Beispiel #24
0
        public FileOperationResult Download(string localName, CopyFlags copyFlags, RemoteInfo info)
        {
            var offset = 0L;

            try
            {
                var file = new FileInfo(localName);
                if (file.Exists && (copyFlags.Equals(CopyFlags.None) || copyFlags.Equals(CopyFlags.Move)))
                {
                    return(FileOperationResult.ExistsResumeAllowed);
                }
                if (copyFlags.IsSet(CopyFlags.Resume))
                {
                    offset = file.Length;
                }
                if (copyFlags.IsSet(CopyFlags.Overwrite))
                {
                    file.Delete();
                }
            }
            catch (Exception ex)
            {
                if (Error != null)
                {
                    Error(ex);
                }
                return(FileOperationResult.WriteError);
            }

            try
            {
                if (Progress != null)
                {
                    Progress(key, localName, offset, info.Size);
                }

                //download
                using (var stream = service.GetObjectStream(bucketName, key, offset))
                    using (var file = new FileStream(localName, FileMode.Append))
                    {
                        var buffer = new byte[1024 * 4];
                        var total  = offset;
                        while (true)
                        {
                            var readed = stream.Read(buffer, 0, buffer.Length);
                            if (readed <= 0)
                            {
                                break;
                            }

                            file.Write(buffer, 0, readed);

                            if (Progress != null && Progress(key, localName, total += readed, info.Size) == false)
                            {
                                return(FileOperationResult.UserAbort);
                            }
                        }
                    }

                if (Progress != null)
                {
                    Progress(key, localName, 100, 100);
                }

                return(FileOperationResult.OK);
            }
            catch (Exception ex)
            {
                if (Error != null)
                {
                    Error(ex);
                }
                return(FileOperationResult.ReadError);
            }
        }
        /// <summary>
        /// This method is used to copy or move all but a specified few properties from a source object to a destination object. 
        /// </summary>
        /// <param name="copyFlag">Specifies the CopyFlags in the call request.</param>
        /// <param name="isWantAsynchronousZero">Indicates whether WantAsynchronous parameter in call request is zero.</param>
        /// <param name="isWantSubObjectsZero">Indicates whether WantSubObjects parameter in call request is zero.</param>
        /// <param name="isDestinationExist">Indicates whether destination object is exist for [RopCopyTo].</param>
        /// <param name="isPropertiesDeleted">If CopyFlags is set to Move,Source object will be deleted after copy to.</param>
        /// <param name="isSubObjectCopied">Indicates whether sub-object properties is also be copied.</param>
        /// <param name="isOverwriteDestination">If CopyFlags is set to NoOverWrite,Destination should not be overwritten.</param>
        /// <param name="isReturnedRopProgress">If this ROP is performed Asynchronously,RopProgress response
        /// returned instead of RopCopyProperties response.</param>
        /// <param name="isChangedInDB">Indicates whether destination is changed in database.</param>
        /// <param name="error">If destination object is not exist,NullDestinationObject error will be returned.</param>
        public void RopCopyToMethod(
            CopyFlags copyFlag,
            bool isWantAsynchronousZero,
            bool isWantSubObjectsZero,
            bool isDestinationExist,
            out bool isPropertiesDeleted,
            out bool isSubObjectCopied,
            out bool isOverwriteDestination,
            out bool isReturnedRopProgress,
            out bool isChangedInDB,
            out CPRPTErrorCode error)
        {
            // Check if there are conflict SHOULD/MAY settings 
            this.CheckRequirementConflict(86702, 18402);
            this.CheckRequirementConflict(86708, 5070506);

            #region Set parameters
            isPropertiesDeleted = false;
            isSubObjectCopied = false;
            isOverwriteDestination = false;
            isReturnedRopProgress = false;
            isChangedInDB = false;
            error = CPRPTErrorCode.None;

            uint secondHandle = InvalidHandle;
            if (isDestinationExist)
            {
                secondHandle = this.cprptSecondHandle;
                if (this.cprptCurrentType == ServerObjectType.Folder)
                {
                    RopCreateFolderResponse createFolderResponse;
                    string displayName = SubFolder;
                    secondHandle = this.RopCreateFolder(secondHandle, out createFolderResponse, displayName, "Comment: " + displayName, true);
                }
            }

            byte copyFlags = (byte)RopCopyToCopyFlags.None;

            switch (copyFlag)
            {
                case CopyFlags.None:
                    copyFlags = (byte)RopCopyToCopyFlags.None;
                    break;
                case CopyFlags.Move:
                    copyFlags = (byte)RopCopyToCopyFlags.Move;
                    break;
                case CopyFlags.NoOverWrite:
                    copyFlags = (byte)RopCopyToCopyFlags.NoOverwrite;
                    break;
                case CopyFlags.MoveAndNoOverWrite:
                    copyFlags = (byte)RopCopyPropertiesCopyFlags.MoveAndOverwrite;
                    break;
                default:
                    copyFlags = (byte)0x05;
                    break;
            }

            // The value indicates whether the ROP is to be processed synchronously or asynchronously, 0 means synchronous operation. 
            byte wantAsynchronous = 0;

            byte wantSubObjects = 1;
            if (isWantSubObjectsZero)
            {
                wantSubObjects = 0;
            }

            PropertyTag[] propertyTags = new PropertyTag[1];
            propertyTags[0] = this.GetTaggedPropertyTag(ObjectToOperate.FirstObject).PropertyTag;
            #endregion

            #region Set the first handle property
            TaggedPropertyValue[] tagPropertyValue = new TaggedPropertyValue[2];
            tagPropertyValue[0] = this.GetTaggedPropertyTag(ObjectToOperate.FirstObject);
            tagPropertyValue[0].Value = Common.AddInt16LengthBeforeBinaryArray(tagPropertyValue[0].Value);
            tagPropertyValue[1] = this.GetTaggedPropertyTag(ObjectToOperate.SecondObject);
            tagPropertyValue[1].Value = Common.AddInt16LengthBeforeBinaryArray(tagPropertyValue[1].Value);

            this.RopSetProperties(this.cprptFirstHandle, tagPropertyValue, true);
            if (this.cprptCurrentType == ServerObjectType.Message)
            {
                this.RopSaveChangesMessage(this.cprptFirstHandle, true);
            }
            else if (this.cprptCurrentType == ServerObjectType.Attachment)
            {
                this.RopSaveChangesAttachment(this.cprptFirstHandle, true);
                this.RopSaveChangesMessage(cprptMessageHandle[0], true);
            }
            #endregion

            #region Set the second handle property
            TaggedPropertyValue[] tagPropertyValue1 = new TaggedPropertyValue[2];
            tagPropertyValue1[0] = this.GetTaggedPropertyTag(ObjectToOperate.FirstObject);
            tagPropertyValue1[0].Value[0] = (byte)(tagPropertyValue1[0].Value[0] + 1);
            tagPropertyValue1[0].Value = Common.AddInt16LengthBeforeBinaryArray(tagPropertyValue1[0].Value);
            tagPropertyValue1[1] = this.GetTaggedPropertyTag(ObjectToOperate.SecondObject);
            tagPropertyValue1[1].Value[0] = (byte)(tagPropertyValue1[1].Value[0] + 1);
            tagPropertyValue1[1].Value = Common.AddInt16LengthBeforeBinaryArray(tagPropertyValue1[1].Value);
            if (isDestinationExist)
            {
                this.RopSetProperties(secondHandle, tagPropertyValue1, true);
                if (this.cprptCurrentType == ServerObjectType.Message)
                {
                    this.RopSaveChangesMessage(secondHandle, true);
                }
                else if (this.cprptCurrentType == ServerObjectType.Attachment)
                {
                    this.RopSaveChangesAttachment(secondHandle, true);
                    this.RopSaveChangesMessage(cprptMessageHandle[0], true);
                }

                // Store the TaggedPropertyValue for further verification
                this.tagPropertyValuesToVerification.Clear();
                switch (this.cprptCurrentType)
                {
                    case ServerObjectType.Folder:
                        this.tagPropertyValuesToVerification.Add(ConstValues.ServerObjectTypeFolderKey, tagPropertyValue1[0]);
                        break;
                    case ServerObjectType.Message:
                        this.tagPropertyValuesToVerification.Add(ConstValues.ServerObjectTypeMessageKey, tagPropertyValue1[0]);
                        break;
                    case ServerObjectType.Attachment:
                        this.tagPropertyValuesToVerification.Add(ConstValues.ServerObjectTypeAttachmentKey, tagPropertyValue1[0]);
                        break;
                    default:
                        break;
                }
            }
            #endregion

            if (!isWantAsynchronousZero)
            {
                wantAsynchronous = 1;
                if (copyFlag != CopyFlags.NoOverWrite && this.cprptCurrentType == ServerObjectType.Folder && !isWantSubObjectsZero)
                {
                    RopCreateMessageResponse createMessageResponse;
                    uint msgHandle = this.RopCreateMessage(cprptFolderHandle[0], cprptFolderId[0], ConstValues.RopCreateMessageAssociatedFlagNone, out createMessageResponse, true);
                    this.RopSaveChangesMessage(msgHandle, true);
                    this.RopRelease(msgHandle);
                }
            }

            // The property set in previous step should exist.
            TaggedPropertyValue existingValue = this.SearchProperty(this.cprptFirstHandle, tagPropertyValue[0].PropertyTag.PropertyId);
            Site.Assert.IsNotNull(existingValue, "The target property should not be null.");

            bool isExcluedPropertyCopied = true;
            PropertyTag[] propertyTag = new PropertyTag[1];
            propertyTag[0] = tagPropertyValue1[1].PropertyTag;
            object responseObj = this.RopCopyTo(this.cprptFirstHandle, secondHandle, (byte)HandleIndex.FirstIndex, (byte)HandleIndex.SecondIndex, wantAsynchronous, wantSubObjects, copyFlags, propertyTag);

            if (isDestinationExist)
            {
                RopGetPropertiesSpecificResponse getPropertiesSpecificResponse = this.RopGetPropertiesSpecific(secondHandle, 0, 0, propertyTag);
                if (!Common.CompareByteArray(getPropertiesSpecificResponse.RowData.PropertyValues[0].Value, tagPropertyValue[0].Value))
                {
                    isExcluedPropertyCopied = false;
                }

                this.VerifyRopCopyToExcludeElement(isExcluedPropertyCopied);
            }

            if (responseObj is RopProgressResponse)
            {
                isReturnedRopProgress = true;
            }
            else
            {
                RopCopyToResponse ropCopyToResponse = (RopCopyToResponse)responseObj;

                this.VerifyRopCopyTo(ropCopyToResponse, CopyToCondition.Normal, this.cprptCurrentType, copyFlag);

                error = (CPRPTErrorCode)ropCopyToResponse.ReturnValue;

                if (!isReturnedRopProgress && isWantAsynchronousZero && ropCopyToResponse.ReturnValue == (uint)RopResponseType.SuccessResponse)
                {
                    #region Check if the property is changed in DB
                    string objKey;
                    switch (this.cprptCurrentType)
                    {
                        case ServerObjectType.Folder:
                            objKey = "Folder2";
                            break;
                        case ServerObjectType.Message:
                            objKey = "Message2";
                            break;
                        case ServerObjectType.Attachment:
                            objKey = "Attachment2";
                            break;
                        default:
                            objKey = string.Empty;
                            break;
                    }

                    bool isPropertyFound;
                    byte[] propertyValueBeforeSave = this.Session2GetPropertyData(objKey, tagPropertyValue[0].PropertyTag, out isPropertyFound);

                    isChangedInDB = !Common.CompareByteArray(propertyValueBeforeSave, tagPropertyValue1[0].Value);
                    #endregion

                    #region Check if the value is overwritten
                    TaggedPropertyValue overwriteValue = this.SearchProperty(secondHandle, tagPropertyValue1[0].PropertyTag.PropertyId);
                    if (Common.CompareByteArray(overwriteValue.Value, tagPropertyValue1[0].Value))
                    {
                        isOverwriteDestination = false;
                    }
                    else
                    {
                        isOverwriteDestination = true;
                    }
                    #endregion

                    #region Check if the sub-object is copied
                    if (!isWantSubObjectsZero && isDestinationExist)
                    {
                        if (this.cprptCurrentType == ServerObjectType.Folder)
                        {
                            TaggedPropertyValue ptagValue = this.SearchProperty(secondHandle, (ushort)TaggedPropertyName.PidTagContentCount);
                            if (ptagValue.Value[0] != 0 || ptagValue.Value[1] != 0 || ptagValue.Value[2] != 0 || ptagValue.Value[3] != 0)
                            {
                                isSubObjectCopied = true;
                            }
                        }
                        else if (this.cprptCurrentType == ServerObjectType.Message)
                        {
                            RopOpenAttachmentResponse openAttRes;
                            this.RopOpenAttachment(secondHandle, cprptAttachmentId[0], out openAttRes, true);
                            if (openAttRes.ReturnValue == (uint)CPRPTErrorCode.None)
                            {
                                isSubObjectCopied = true;
                            }
                        }
                    }
                    #endregion

                    #region Check if the value is deleted
                    // The message and attachment objects must apply the changes to database
                    if (this.cprptCurrentType == ServerObjectType.Message)
                    {
                        this.RopSaveChangesMessage(this.cprptFirstHandle, true);
                    }
                    else if (this.cprptCurrentType == ServerObjectType.Attachment)
                    {
                        this.RopSaveChangesAttachment(this.cprptFirstHandle, false);
                        this.RopSaveChangesMessage(cprptMessageHandle[0], false);
                    }

                    switch (this.cprptCurrentType)
                    {
                        case ServerObjectType.Folder:
                            objKey = ConstValues.ServerObjectTypeFolderKey;
                            break;
                        case ServerObjectType.Message:
                            objKey = ConstValues.ServerObjectTypeMessageKey;
                            break;
                        case ServerObjectType.Attachment:
                            objKey = ConstValues.ServerObjectTypeAttachmentKey;
                            break;
                        default:
                            objKey = string.Empty;
                            break;
                    }

                    if (this.cprptCurrentType == ServerObjectType.Folder)
                    {
                        TaggedPropertyValue deleteValue = this.SearchProperty(this.cprptFirstHandle, tagPropertyValue[0].PropertyTag.PropertyId);
                        if (deleteValue == null)
                        {
                            isPropertiesDeleted = true;
                        }
                    }
                    else
                    {
                        if (this.cprptCurrentType == ServerObjectType.Attachment && copyFlag == CopyFlags.Move && Common.IsRequirementEnabled(86707, this.Site))
                        {
                            isPropertiesDeleted = true;
                        }
                        else
                        {
                            byte[] propertyValueNow = this.Session2GetPropertyData(objKey, tagPropertyValue[0].PropertyTag, out isPropertyFound);
                            if (!isPropertyFound)
                            {
                                isPropertiesDeleted = true;
                            }
                            else
                            {
                                byte[] expectedNotFoundError = new byte[] { 0x0f, 0x01, 0x04, 0x80 };
                                isPropertiesDeleted = Common.CompareByteArray(expectedNotFoundError, propertyValueNow);
                            }
                        }
                    }
                    #endregion
                }
            }
        }
Beispiel #26
0
        public FileOperationResult Upload(string localName, CopyFlags copyFlags)
        {
            if (copyFlags.IsSet(CopyFlags.ExistsSameCase) && !copyFlags.IsSet(CopyFlags.Overwrite))
            {
                return(FileOperationResult.Exists);
            }

            var aborted = false;

            try
            {
                var localFile = new FileInfo(localName);
                if (!localFile.Exists)
                {
                    return(FileOperationResult.NotFound);
                }
                var length = localFile.Length;

                if (Progress != null)
                {
                    Progress(localName, key, 0, length);
                }

                service.AddObject(
                    bucketName,
                    key,
                    localFile.Length,
                    MimeMapping.GetMimeMapping(localName),
                    stream =>
                {
                    using (var file = localFile.OpenRead())
                    {
                        var buffer = new byte[1024];
                        var total  = 0;
                        while (true)
                        {
                            var readed = file.Read(buffer, 0, buffer.Length);
                            if (readed <= 0)
                            {
                                break;
                            }

                            stream.Write(buffer, 0, readed);

                            if (Progress != null && Progress(localName, key, total += readed, length) == false)
                            {
                                aborted = true;
                                return;
                            }
                        }
                    }
                }
                    );

                if (Progress != null)
                {
                    Progress(localName, key, 100, 100);
                }

                return(FileOperationResult.OK);
            }
            catch (Exception ex)
            {
                if (aborted)
                {
                    return(FileOperationResult.UserAbort);
                }

                if (Error != null)
                {
                    Error(ex);
                }
                return(FileOperationResult.WriteError);
            }
        }
Beispiel #27
0
 public void EmitBinOp(BinaryOperator binOp, MachineOperand dst, DataType dtDst, Expression left, Expression right, CopyFlags flags)
 {
     if (right is Constant c)
     {
         if (c.DataType.BitSize < left.DataType.BitSize)
         {
             right = m.Const(left.DataType, c.ToInt64());
         }
     }
     EmitCopy(dst, new BinaryExpression(binOp, dtDst, left, right), flags);
 }
 public virtual FileOperationResult FilePut(string localName, ref string remoteName, CopyFlags copyFlags)
 {
     return FileOperationResult.Default;
 }
        internal string GetCmdLineParams(string sourceDirectory = null, string destDirectory = null)
        {
            StringBuilder cmdText = new StringBuilder();

            if (!sourceDirectory.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" \"{0}\"", sourceDirectory);
            }
            else if (!SourceDirectory.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" \"{0}\"", SourceDirectory);
            }

            if (!destDirectory.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" \"{0}\"", destDirectory);
            }
            else if (!DestDirectory.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" \"{0}\"", DestDirectory);
            }

            if (!Files.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" {0}", Files);
            }
            else
            {
                cmdText.Append("*.*");
            }

            //Copy Options
            if (CopyNoEmptySubDirectories)
            {
                cmdText.Append(" /S");
            }
            if (CopySubDirectories)
            {
                cmdText.Append(" /E");
            }
            if (OnlyCopyNLevels > 0)
            {
                cmdText.AppendFormat(" /LEV:{0}", OnlyCopyNLevels);
            }
            if (CopyFilesRestartableMode)
            {
                cmdText.Append(" /Z");
            }
            if (CopyFilesBackupMode)
            {
                cmdText.Append(" /B");
            }
            if (FallbackCopyFilesMode)
            {
                cmdText.Append(" /ZB");
            }
            if (UnbufferredIOCopy)
            {
                cmdText.Append(" /J");
            }

            if (EncrptFileEFSRawMode)
            {
                cmdText.Append(" /EFSRAW");
            }
            if (!CopyFlags.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /COPY:{0}", (from f in CopyFlags.SplitNTrim()
                                                    where !f.IsNullOrWhiteSpace()
                                                    select((ChoCopyFlags)Enum.Parse(typeof(ChoCopyFlags), f)).ToDescription()).Join(""));
            }
            if (CopyDirTimestamp)
            {
                cmdText.Append(" /DCOPY:T");
            }
            if (CopyFilesWithSecurity)
            {
                cmdText.Append(" /SEC");
            }

            if (CopyFilesWithFileInfo)
            {
                cmdText.Append(" /COPYALL");
            }
            if (CopyFilesWithNoFileInfo)
            {
                cmdText.Append(" /NOCOPY");
            }
            if (FixFileSecurityOnFiles)
            {
                cmdText.Append(" /SECFIX");
            }
            if (FixFileTimeOnFiles)
            {
                cmdText.Append(" /TIMFIX");
            }

            if (DelDestFileDirIfNotExistsInSource)
            {
                cmdText.Append(" /PURGE");
            }
            if (MirrorDirTree)
            {
                cmdText.Append(" /MIR");
            }
            if (MoveFiles)
            {
                cmdText.Append(" /MOV");
            }
            if (MoveFilesNDirs)
            {
                cmdText.Append(" /MOVE");
            }
            if (!AddFileAttributes.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /A+:{0}", (from f in AddFileAttributes.SplitNTrim()
                                                  where !f.IsNullOrWhiteSpace()
                                                  select((ChoFileAttributes)Enum.Parse(typeof(ChoFileAttributes), f)).ToDescription()).Join(""));
            }
            if (!RemoveFileAttributes.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /A-:{0}", (from f in RemoveFileAttributes.SplitNTrim()
                                                  where !f.IsNullOrWhiteSpace()
                                                  select((ChoFileAttributes)Enum.Parse(typeof(ChoFileAttributes), f)).ToDescription()).Join(""));
            }
            if (CreateDirTree)
            {
                cmdText.Append(" /CREATE");
            }
            if (CreateFATFileNames)
            {
                cmdText.Append(" /FAT");
            }
            if (TurnOffLongPath)
            {
                cmdText.Append(" /256");
            }

            if (RunAgainWithNoChangesSeen > 0)
            {
                cmdText.AppendFormat(" /MON:{0}", RunAgainWithNoChangesSeen);
            }
            if (RunAgainWithChangesSeenInMin > 0)
            {
                cmdText.AppendFormat(" /MOT:{0}", RunAgainWithChangesSeenInMin);
            }
            if (RunHourStartTime != TimeSpan.Zero &&
                RunHourEndTime != TimeSpan.Zero &&
                RunHourStartTime < RunHourEndTime)
            {
                cmdText.AppendFormat(" /RH:{0}-{1}", RunHourStartTime.ToString("hhmm"), RunHourEndTime.ToString("hhmm"));
            }
            if (CheckRunHourPerFileBasis)
            {
                cmdText.Append(" /PF");
            }
            if (InterPacketGapInMS > 0)
            {
                cmdText.AppendFormat(" /IPG:{0}", InterPacketGapInMS);
            }
            if (CopySymbolicLinks)
            {
                cmdText.Append(" /SL");
            }
            if (MultithreadCopy > 0)
            {
                cmdText.AppendFormat(" /MT:{0}", MultithreadCopy);
            }
            if (CopyNODirInfo)
            {
                cmdText.Append(" /NODCOPY");
            }
            if (CopyWithoutWindowsCopyOffload)
            {
                cmdText.Append(" /NOOFFLOAD");
            }

            //File Selection Options
            if (CopyOnlyFilesWithArchiveAttributes)
            {
                cmdText.Append(" /A");
            }
            if (CopyOnlyFilesWithArchiveAttributesAndReset)
            {
                cmdText.Append(" /M");
            }
            if (!IncludeFilesWithGivenAttributes.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /IA:{0}", IncludeFilesWithGivenAttributes);
            }
            if (!ExcludeFilesWithGivenAttributes.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /XA:{0}", ExcludeFilesWithGivenAttributes);
            }
            if (!ExcludeFilesWithGivenNames.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /XF {0}", ExcludeFilesWithGivenNames.Replace(";", " "));
            }
            if (!ExcludeDirsWithGivenNames.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /XD {0}", ExcludeDirsWithGivenNames.Replace(";", " "));
            }
            if (ExcludeChangedFiles)
            {
                cmdText.Append(" /XC");
            }
            if (ExcludeNewerFiles)
            {
                cmdText.Append(" /XN");
            }
            if (ExcludeOlderFiles)
            {
                cmdText.Append(" /XO");
            }
            if (ExcludeExtraFilesAndDirs)
            {
                cmdText.Append(" /XX");
            }
            if (ExcludeLonelyFilesAndDirs)
            {
                cmdText.Append(" /XL");
            }
            if (IncludeSameFiles)
            {
                cmdText.Append(" /IS");
            }
            if (IncludeTweakedFiles)
            {
                cmdText.Append(" /IT");
            }

            if (ExcludeFilesBiggerThanNBytes > 0)
            {
                cmdText.AppendFormat(" /MAX:{0}", ExcludeFilesBiggerThanNBytes);
            }
            if (ExcludeFilesSmallerThanNBytes > 0)
            {
                cmdText.AppendFormat(" /MIN:{0}", ExcludeFilesSmallerThanNBytes);
            }

            if (ExcludeFilesOlderThanNDays > 0)
            {
                cmdText.AppendFormat(" /MAXAGE:{0}", ExcludeFilesOlderThanNDays);
            }
            if (ExcludeFilesNewerThanNDays > 0)
            {
                cmdText.AppendFormat(" /MINAGE:{0}", ExcludeFilesNewerThanNDays);
            }
            if (ExcludeFilesUnusedSinceNDays > 0)
            {
                cmdText.AppendFormat(" /MAXLAD:{0}", ExcludeFilesUnusedSinceNDays);
            }
            if (ExcludeFilesUsedSinceNDays > 0)
            {
                cmdText.AppendFormat(" /MINLAD:{0}", ExcludeFilesUsedSinceNDays);
            }

            if (ExcludeJunctionPoints)
            {
                cmdText.Append(" /XJ");
            }
            if (AssumeFATFileTimes)
            {
                cmdText.Append(" /FFT");
            }
            if (CompensateOneHourDSTTimeDiff)
            {
                cmdText.Append(" /DST");
            }
            if (ExcludeJunctionPointsForDirs)
            {
                cmdText.Append(" /XJD");
            }
            if (ExcludeJunctionPointsForFiles)
            {
                cmdText.Append(" /XJF");
            }

            //Retry Options
            if (NoOfRetries > 0)
            {
                cmdText.AppendFormat(" /R:{0}", NoOfRetries);
            }
            if (WaitTimeBetweenRetries > 0)
            {
                cmdText.AppendFormat(" /W:{0}", WaitTimeBetweenRetries);
            }
            if (SaveRetrySettingsToRegistry)
            {
                cmdText.Append(" /REG");
            }
            if (WaitForSharenames)
            {
                cmdText.Append(" /TBD");
            }

            //Logging Options
            if (ListOnly)
            {
                cmdText.Append(" /L");
            }
            if (ReportExtraFiles)
            {
                cmdText.Append(" /X");
            }
            if (VerboseOutput)
            {
                cmdText.Append(" /V");
            }
            if (IncludeSourceFileTimestamp)
            {
                cmdText.Append(" /TS");
            }
            if (IncludeFullPathName)
            {
                cmdText.Append(" /FP");
            }
            if (PrintByteSizes)
            {
                cmdText.Append(" /BYTES");
            }
            if (NoFileSizeLog)
            {
                cmdText.Append(" /NS");
            }
            if (NoFileClassLog)
            {
                cmdText.Append(" /NC");
            }
            if (NoFileNameLog)
            {
                cmdText.Append(" /NFL");
            }
            if (NoDirListLog)
            {
                cmdText.Append(" /NDL");
            }
            if (NoProgress)
            {
                cmdText.Append(" /NP");
            }
            if (ShowEstTimeOfArrival)
            {
                cmdText.Append(" /ETA");
            }
            if (!OutputLogFilePath.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /LOG:{0}", OutputLogFilePath);
            }
            if (!AppendOutputLogFilePath.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /LOG+:{0}", AppendOutputLogFilePath);
            }
            if (!UnicodeOutputLogFilePath.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /UNILOG:{0}", UnicodeOutputLogFilePath);
            }
            if (!AppendUnicodeOutputLogFilePath.IsNullOrWhiteSpace())
            {
                cmdText.AppendFormat(" /UNILOG+:{0}", AppendUnicodeOutputLogFilePath);
            }
            if (NoJobHeader)
            {
                cmdText.Append(" /NJH");
            }
            if (NoJobSummary)
            {
                cmdText.Append(" /NJS");
            }

            return(cmdText.ToString());
        }
Beispiel #30
0
 public static extern bool CopyFileExW(string src, string dst, IntPtr state, IntPtr data, bool cancel, CopyFlags flags);
Beispiel #31
0
        public void EmitBinOp(BinaryOperator binOp, MachineOperand dst, DataType dtDst, Expression left, Expression right, CopyFlags flags)
        {
            Constant c = right as Constant;

            if (c != null)
            {
                if (c.DataType == PrimitiveType.Byte && left.DataType != c.DataType)
                {
                    right = emitter.Const(left.DataType, c.ToInt32());
                }
            }
            //EmitCopy(dst, new BinaryExpression(binOp, dtDst, left, right), true, emitCc);
            EmitCopy(dst, new BinaryExpression(binOp, dtDst, left, right), flags);
        }
Beispiel #32
0
        /// <summary>
        /// Performs a buffer to buffer, or buffer to texture copy.
        /// </summary>
        /// <param name="state">Current GPU state</param>
        /// <param name="argument">Method call argument</param>
        private void CopyBuffer(GpuState state, int argument)
        {
            var cbp = state.Get <CopyBufferParams>(MethodOffset.CopyBufferParams);

            var swizzle = state.Get <CopyBufferSwizzle>(MethodOffset.CopyBufferSwizzle);

            CopyFlags copyFlags = (CopyFlags)argument;

            bool srcLinear = copyFlags.HasFlag(CopyFlags.SrcLinear);
            bool dstLinear = copyFlags.HasFlag(CopyFlags.DstLinear);
            bool copy2D    = copyFlags.HasFlag(CopyFlags.MultiLineEnable);
            bool remap     = copyFlags.HasFlag(CopyFlags.RemapEnable);

            int size = cbp.XCount;

            if (size == 0)
            {
                return;
            }

            FlushUboUpdate();

            if (copy2D)
            {
                // Buffer to texture copy.
                int srcBpp = remap ? swizzle.UnpackSrcComponentsCount() * swizzle.UnpackComponentSize() : 1;
                int dstBpp = remap ? swizzle.UnpackDstComponentsCount() * swizzle.UnpackComponentSize() : 1;

                var dst = state.Get <CopyBufferTexture>(MethodOffset.CopyBufferDstTexture);
                var src = state.Get <CopyBufferTexture>(MethodOffset.CopyBufferSrcTexture);

                var srcCalculator = new OffsetCalculator(
                    src.Width,
                    src.Height,
                    cbp.SrcStride,
                    srcLinear,
                    src.MemoryLayout.UnpackGobBlocksInY(),
                    src.MemoryLayout.UnpackGobBlocksInZ(),
                    srcBpp);

                var dstCalculator = new OffsetCalculator(
                    dst.Width,
                    dst.Height,
                    cbp.DstStride,
                    dstLinear,
                    dst.MemoryLayout.UnpackGobBlocksInY(),
                    dst.MemoryLayout.UnpackGobBlocksInZ(),
                    dstBpp);

                ulong srcBaseAddress = _context.MemoryManager.Translate(cbp.SrcAddress.Pack());
                ulong dstBaseAddress = _context.MemoryManager.Translate(cbp.DstAddress.Pack());

                (int srcBaseOffset, int srcSize) = srcCalculator.GetRectangleRange(src.RegionX, src.RegionY, cbp.XCount, cbp.YCount);
                (int dstBaseOffset, int dstSize) = dstCalculator.GetRectangleRange(dst.RegionX, dst.RegionY, cbp.XCount, cbp.YCount);

                ReadOnlySpan <byte> srcSpan = _context.PhysicalMemory.GetSpan(srcBaseAddress + (ulong)srcBaseOffset, srcSize, true);
                Span <byte>         dstSpan = _context.PhysicalMemory.GetSpan(dstBaseAddress + (ulong)dstBaseOffset, dstSize).ToArray();

                bool completeSource = IsTextureCopyComplete(cbp, src, srcLinear, srcBpp, cbp.SrcStride);
                bool completeDest   = IsTextureCopyComplete(cbp, dst, dstLinear, dstBpp, cbp.DstStride);

                if (completeSource && completeDest)
                {
                    Image.Texture target = TextureManager.FindTexture(dst, cbp, swizzle, dstLinear);
                    if (target != null)
                    {
                        ReadOnlySpan <byte> data;
                        if (srcLinear)
                        {
                            data = LayoutConverter.ConvertLinearStridedToLinear(
                                target.Info.Width,
                                target.Info.Height,
                                1,
                                1,
                                cbp.SrcStride,
                                target.Info.FormatInfo.BytesPerPixel,
                                srcSpan);
                        }
                        else
                        {
                            data = LayoutConverter.ConvertBlockLinearToLinear(
                                src.Width,
                                src.Height,
                                1,
                                target.Info.Levels,
                                1,
                                1,
                                1,
                                srcBpp,
                                src.MemoryLayout.UnpackGobBlocksInY(),
                                src.MemoryLayout.UnpackGobBlocksInZ(),
                                1,
                                new SizeInfo((int)target.Size),
                                srcSpan);
                        }

                        target.SetData(data);
                        target.SignalModified();

                        return;
                    }
                    else if (srcCalculator.LayoutMatches(dstCalculator))
                    {
                        srcSpan.CopyTo(dstSpan); // No layout conversion has to be performed, just copy the data entirely.

                        _context.PhysicalMemory.Write(dstBaseAddress + (ulong)dstBaseOffset, dstSpan);

                        return;
                    }
                }

                unsafe bool Convert <T>(Span <byte> dstSpan, ReadOnlySpan <byte> srcSpan) where T : unmanaged
                {
                    fixed(byte *dstPtr = dstSpan, srcPtr = srcSpan)
                    {
                        byte *dstBase = dstPtr - dstBaseOffset; // Layout offset is relative to the base, so we need to subtract the span's offset.
                        byte *srcBase = srcPtr - srcBaseOffset;

                        for (int y = 0; y < cbp.YCount; y++)
                        {
                            srcCalculator.SetY(src.RegionY + y);
                            dstCalculator.SetY(dst.RegionY + y);

                            for (int x = 0; x < cbp.XCount; x++)
                            {
                                int srcOffset = srcCalculator.GetOffset(src.RegionX + x);
                                int dstOffset = dstCalculator.GetOffset(dst.RegionX + x);

                                *(T *)(dstBase + dstOffset) = *(T *)(srcBase + srcOffset);
                            }
                        }
                    }

                    return(true);
                }

                bool _ = srcBpp switch
                {
                    1 => Convert <byte>(dstSpan, srcSpan),
                    2 => Convert <ushort>(dstSpan, srcSpan),
                    4 => Convert <uint>(dstSpan, srcSpan),
                    8 => Convert <ulong>(dstSpan, srcSpan),
                    12 => Convert <Bpp12Pixel>(dstSpan, srcSpan),
                    16 => Convert <Vector128 <byte> >(dstSpan, srcSpan),
                    _ => throw new NotSupportedException($"Unable to copy ${srcBpp} bpp pixel format.")
                };

                _context.PhysicalMemory.Write(dstBaseAddress + (ulong)dstBaseOffset, dstSpan);
            }
            else
            {
                if (remap &&
                    swizzle.UnpackDstX() == BufferSwizzleComponent.ConstA &&
                    swizzle.UnpackDstY() == BufferSwizzleComponent.ConstA &&
                    swizzle.UnpackDstZ() == BufferSwizzleComponent.ConstA &&
                    swizzle.UnpackDstW() == BufferSwizzleComponent.ConstA &&
                    swizzle.UnpackSrcComponentsCount() == 1 &&
                    swizzle.UnpackDstComponentsCount() == 1 &&
                    swizzle.UnpackComponentSize() == 4)
                {
                    // Fast path for clears when remap is enabled.
                    BufferManager.ClearBuffer(cbp.DstAddress, (uint)size * 4, state.Get <uint>(MethodOffset.CopyBufferConstA));
                }
                else
                {
                    // TODO: Implement remap functionality.
                    // Buffer to buffer copy.
                    BufferManager.CopyBuffer(cbp.SrcAddress, cbp.DstAddress, (uint)size);
                }
            }
        }
        /// <summary>
        /// Parse the RopCopyToRequest structure.
        /// </summary>
        /// <param name="s">An stream containing RopCopyToRequest structure.</param>
        public override void Parse(Stream s)
        {
            base.Parse(s);

            this.RopId = (RopIdType)ReadByte();
            this.LogonId = ReadByte();
            this.SourceHandleIndex = ReadByte();
            this.DestHandleIndex = ReadByte();
            this.WantAsynchronous = ReadBoolean();
            this.WantSubObjects = ReadBoolean();
            this.CopyFlags = (CopyFlags)ReadByte();
            this.ExcludedTagCount = ReadUshort();
            this.ExcludedTags = new PropertyTag[(int)this.ExcludedTagCount];
            for (int i = 0; i < this.ExcludedTagCount; i++)
            {
                ExcludedTags[i] = new PropertyTag();
                ExcludedTags[i].Parse(s);
            }
        }
        public static void RopCopyPropertiesMethodCall(CopyFlags copyFlag, bool isWantAsynchronousZero, bool isDestinationExist)
        {
            Condition.IsTrue(
                isInitialized && isFirstObjectGot && isSecondObjectGot &&
                (globalObj == ServerObjectType.Message ||
                globalObj == ServerObjectType.Attachment ||
                globalObj == ServerObjectType.Folder));

            clientCopyFlag = copyFlag;
            isClientWantAsynchronous = !isWantAsynchronousZero;
            isDestinationInRequestExist = isDestinationExist;
        }
Beispiel #35
0
 private void RewriteUnaryOperator(UnaryOperator op, MachineOperand opDst, MachineOperand opSrc, CopyFlags flags)
 {
     EmitCopy(opDst, new UnaryExpression(op, opSrc.Width, SrcOp(opSrc)), flags);
 }
Beispiel #36
0
        public override FileSystemExitCode GetFile(string remoteName, ref string localName, CopyFlags copyFlags,
                                                   RemoteInfo remoteInfo)
        {
            bool overWrite = (CopyFlags.Overwrite & copyFlags) != 0;

            remoteName = remoteName.Substring(1);

            if (File.Exists(localName) & !overWrite)
            {
                return(FileSystemExitCode.FileExists);
            }
            try {
                if ((CopyFlags.Move & copyFlags) != 0)
                {
                    MoveFileOptions options =
                        (overWrite) ? MoveFileOptions.ReplaceExisting : MoveFileOptions.None;
                    FileRoutines.MoveFile(new FileInfo(remoteName), new FileInfo(localName),
                                          options, OnCopyFile);
                }
                else
                {
                    CopyFileOptions options =
                        (overWrite) ? CopyFileOptions.None : CopyFileOptions.FailIfDestinationExists;
                    FileRoutines.CopyFile(new FileInfo(remoteName), new FileInfo(localName),
                                          options, OnCopyFile);
                }
                return(FileSystemExitCode.OK);
            } catch (Exception ex) {
                MessageBox.Show(
                    "File operation error:" + Environment.NewLine + ex.Message,
                    "LFS Plugin (GetFile)", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(FileSystemExitCode.ReadError);
            }
        }