Exemplo n.º 1
0
        private void UnlockFile(long offset, long count)
        {
#if !SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME && !SILICONSTUDIO_PLATFORM_MONO_MOBILE
            var fileStream = stream as FileStream;
            if (fileStream == null)
            {
                return;
            }

#if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
            var countLow  = (uint)count;
            var countHigh = (uint)(count >> 32);

            var overlapped = new NativeLockFile.OVERLAPPED()
            {
                internalLow  = 0,
                internalHigh = 0,
                offsetLow    = (uint)offset,
                offsetHigh   = (uint)(offset >> 32),
                hEvent       = IntPtr.Zero,
            };

            if (!NativeLockFile.UnlockFileEx(fileStream.SafeFileHandle, 0, countLow, countHigh, ref overlapped))
            {
                throw new IOException("Couldn't unlock file.");
            }
#else
            fileStream.Unlock(offset, count);
#endif
#endif
        }
Exemplo n.º 2
0
        private void LockFile(long offset, long count, bool exclusive)
        {
#if !SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
            var fileStream = stream as FileStream;
            if (fileStream == null)
            {
                return;
            }

#if SILICONSTUDIO_PLATFORM_ANDROID
            // Android does not support large file and thus is limited to files
            // whose sizes are less than 2GB.
            // We substract the offset to not go beyond the 2GB limit.
            count = (count + offset > int.MaxValue) ? int.MaxValue - offset: count;
#endif

#if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
            var countLow  = (uint)count;
            var countHigh = (uint)(count >> 32);

            var overlapped = new NativeLockFile.OVERLAPPED()
            {
                internalLow  = 0,
                internalHigh = 0,
                offsetLow    = (uint)offset,
                offsetHigh   = (uint)(offset >> 32),
                hEvent       = IntPtr.Zero,
            };

            if (!NativeLockFile.LockFileEx(fileStream.SafeFileHandle, exclusive ? NativeLockFile.LOCKFILE_EXCLUSIVE_LOCK : 0, 0, countLow, countHigh, ref overlapped))
            {
                throw new IOException("Couldn't lock file.");
            }
#elif SILICONSTUDIO_RUNTIME_CORECLR
            // There is no implementation of FileStream.Lock on CoreCLR
#else
            bool tryAgain;
            do
            {
                tryAgain = false;
                try
                {
                    fileStream.Lock(offset, count);
                }
                catch (IOException)
                {
                    tryAgain = true;
                }
            } while (tryAgain);
#endif
#endif
        }
Exemplo n.º 3
0
        private void LockFile(long offset, long count, bool exclusive)
        {
#if !SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME && !SILICONSTUDIO_PLATFORM_MONO_MOBILE
            var fileStream = stream as FileStream;
            if (fileStream == null)
            {
                return;
            }

#if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
            var countLow  = (uint)count;
            var countHigh = (uint)(count >> 32);

            var overlapped = new NativeLockFile.OVERLAPPED()
            {
                internalLow  = 0,
                internalHigh = 0,
                offsetLow    = (uint)offset,
                offsetHigh   = (uint)(offset >> 32),
                hEvent       = IntPtr.Zero,
            };

            if (!NativeLockFile.LockFileEx(fileStream.SafeFileHandle, exclusive ? NativeLockFile.LOCKFILE_EXCLUSIVE_LOCK : 0, 0, countLow, countHigh, ref overlapped))
            {
                throw new IOException("Couldn't lock file.");
            }
#elif SILICONSTUDIO_RUNTIME_CORECLR
            // There is no implementation of FileStream.Lock on CoreCLR
#else
            bool tryAgain;
            do
            {
                tryAgain = false;
                try
                {
                    fileStream.Lock(offset, count);
                }
                catch (IOException)
                {
                    tryAgain = true;
                }
            } while (tryAgain);
#endif
#endif
        }
Exemplo n.º 4
0
        private void UnlockFile(long offset, long count)
        {
#if !SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
            var fileStream = stream as FileStream;
            if (fileStream == null)
            {
                return;
            }

#if SILICONSTUDIO_PLATFORM_ANDROID
            // See comment on `LockFile`.
            count = (count + offset > int.MaxValue) ? int.MaxValue - offset: count;
#endif

#if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
            var countLow  = (uint)count;
            var countHigh = (uint)(count >> 32);

            var overlapped = new NativeLockFile.OVERLAPPED()
            {
                internalLow  = 0,
                internalHigh = 0,
                offsetLow    = (uint)offset,
                offsetHigh   = (uint)(offset >> 32),
                hEvent       = IntPtr.Zero,
            };

            if (!NativeLockFile.UnlockFileEx(fileStream.SafeFileHandle, 0, countLow, countHigh, ref overlapped))
            {
                throw new IOException("Couldn't unlock file.");
            }
#elif SILICONSTUDIO_RUNTIME_CORECLR
            // There is no implementation of FileStream.Unlock on CoreCLR
#else
            fileStream.Unlock(offset, count);
#endif
#endif
        }