Beispiel #1
0
        // Token: 0x06002221 RID: 8737 RVA: 0x0009F690 File Offset: 0x0009D890
        public static SafeFileHandle OpenFile(string filename, bool openForRead, out int lastError, bool cachedIo)
        {
            FileMode   fileMode;
            FileShare  fileShare;
            FileAccess fileAccess;

            if (openForRead)
            {
                fileMode   = FileMode.Open;
                fileShare  = FileShare.Read;
                fileAccess = FileAccess.Read;
            }
            else
            {
                fileMode   = FileMode.Create;
                fileShare  = FileShare.None;
                fileAccess = FileAccess.Write;
            }
            FileFlags fileFlags;

            if (cachedIo)
            {
                fileFlags = FileFlags.FILE_ATTRIBUTE_NORMAL;
            }
            else
            {
                fileFlags = FileFlags.FILE_FLAG_NO_BUFFERING;
            }
            if (RegistryParameters.LogCopyBufferedIo != 0)
            {
                fileFlags = FileFlags.FILE_ATTRIBUTE_NORMAL;
            }
            return(LogCopy.LogCopyCreateFile(filename, fileAccess, fileShare, fileMode, fileFlags, out lastError));
        }
        internal static void TruncateFile(string fileName, long fileSize)
        {
            int num;

            using (SafeFileHandle safeFileHandle = LogCopy.LogCopyCreateFile(fileName, FileAccess.Write, FileShare.None, FileMode.Open, FileFlags.FILE_ATTRIBUTE_NORMAL, out num))
            {
                long num2;
                NativeMethods.SetFilePointerEx(safeFileHandle, fileSize, out num2, 0U);
                NativeMethods.SetEndOfFile(safeFileHandle);
            }
        }
Beispiel #3
0
        // Token: 0x06002223 RID: 8739 RVA: 0x0009F760 File Offset: 0x0009D960
        public static SafeFileHandle OpenLogForRead(string filename)
        {
            int        num        = 0;
            int        num2       = 300;
            Exception  ex         = null;
            ExDateTime?exDateTime = null;
            FileFlags  fileFlags  = FileFlags.FILE_FLAG_NO_BUFFERING;

            if (RegistryParameters.LogCopyBufferedIo != 0)
            {
                fileFlags = FileFlags.FILE_ATTRIBUTE_NORMAL;
            }
            for (;;)
            {
                int num3 = 0;
                try
                {
                    return(LogCopy.LogCopyCreateFile(filename, FileAccess.Read, FileShare.Read, FileMode.Open, fileFlags, out num3));
                }
                catch (IOException ex2)
                {
                    ex = ex2;
                    if (num3 == 32)
                    {
                        if (num++ == 0)
                        {
                            exDateTime = new ExDateTime?(ExDateTime.Now.AddSeconds((double)RegistryParameters.FileInUseRetryLimitInSecs));
                        }
                        else
                        {
                            if (exDateTime.Value <= ExDateTime.Now)
                            {
                                break;
                            }
                            num2 = 1000;
                        }
                        ExTraceGlobals.LogCopyTracer.TraceError <string, int>(0L, "OpenLogForRead({0}) caught sharing violation. Will retry in {1}ms", filename, num2);
                        Thread.Sleep(num2);
                        continue;
                    }
                }
                break;
            }
            ExTraceGlobals.LogCopyTracer.TraceError <string, Exception>(0L, "OpenLogForRead({0}) failed: {1}", filename, ex);
            throw ex;
        }