~haggai-eran/nux/rtl-rebased

« back to all changes in this revision

Viewing changes to NuxCore/FileManager/NFileManagerWindows.cpp

  • Committer: Jay Taoko
  • Date: 2011-10-21 23:49:15 UTC
  • mfrom: (508.1.2 nux-20)
  • Revision ID: jay.taoko@canonical.com-20111021234915-hnzakb5ndebica8i
* Removed custom Nux types: t_u32, t_s32, t_bool, ...

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
{
28
28
 
29
29
// Choose the size so it is a power of 2. Example (size-1)= 11111111.
30
 
  const t_int  NWindowsSerialFileReader::sBufferSize = 1024;
 
30
  const int  NWindowsSerialFileReader::sBufferSize = 1024;
31
31
 
32
32
  NWindowsSerialFileReader::NWindowsSerialFileReader (HANDLE InHandle, LogOutputDevice &InError)
33
33
    :   m_FileHandle    (InHandle)
49
49
    }
50
50
  }
51
51
 
52
 
  bool NWindowsSerialFileReader::Precache (t_int PrecacheOffset, t_int PrecacheSize)
 
52
  bool NWindowsSerialFileReader::Precache (int PrecacheOffset, int PrecacheSize)
53
53
  {
54
54
    // Only pre-cache at current position and avoid work if pre-caching same offset twice.
55
55
    if ( (m_FilePos == PrecacheOffset) && (!m_BufferBase || !m_BufferCount || m_BufferBase != m_FilePos) )
57
57
      m_BufferBase = m_FilePos;
58
58
      // (sBufferSize - 1) contains only '1', i.e 1111111111.
59
59
      // So (m_FilePos & (sBufferSize-1)) is equal to m_FilePos if m_FilePos <= (sBufferSize-1).
60
 
      m_BufferCount = Min<t_s64> (Min<t_s64> (PrecacheSize, (t_int) (sBufferSize - (m_FilePos & (sBufferSize - 1) ) ) ), m_FileSize - m_FilePos);
61
 
      t_u32 Count = 0;
 
60
      m_BufferCount = Min<long long> (Min<long long> (PrecacheSize, (int) (sBufferSize - (m_FilePos & (sBufferSize - 1) ) ) ), m_FileSize - m_FilePos);
 
61
      unsigned int Count = 0;
62
62
      //GTotalBytesReadViaFileManager += m_BufferCount;
63
63
      ::ReadFile (m_FileHandle, m_Buffer, m_BufferCount, NUX_REINTERPRET_CAST (DWORD *, &Count), NULL);
64
64
 
72
72
    return TRUE;
73
73
  }
74
74
 
75
 
  t_s64 NWindowsSerialFileReader::Seek (t_s64 InPos, NSerializer::SeekPos seekpos)
 
75
  long long NWindowsSerialFileReader::Seek (long long InPos, NSerializer::SeekPos seekpos)
76
76
  {
77
77
    nuxAssert (InPos >= 0);
78
78
    nuxAssert (InPos <= m_FileSize);
109
109
    return filepos.QuadPart;
110
110
  }
111
111
 
112
 
  t_s64 NWindowsSerialFileReader::Tell()
 
112
  long long NWindowsSerialFileReader::Tell()
113
113
  {
114
114
//     Flush();
115
115
//     LARGE_INTEGER pos;
121
121
    return m_FilePos;
122
122
  }
123
123
 
124
 
  t_s64 NWindowsSerialFileReader::GetFileSize()
 
124
  long long NWindowsSerialFileReader::GetFileSize()
125
125
  {
126
126
    nuxAssert (m_FileHandle);
127
127
 
128
128
    if (m_FileHandle == NULL)
129
129
      return -1;
130
130
 
131
 
    t_s64 Size = 0;
 
131
    long long Size = 0;
132
132
 
133
133
    if (::GetFileSizeEx (m_FileHandle, NUX_REINTERPRET_CAST (PLARGE_INTEGER, &Size) ) == 0)
134
134
    {
150
150
    return !m_ErrorCode;
151
151
  }
152
152
 
153
 
  void NWindowsSerialFileReader::SerializeFinal (void *Dest, t_s64 Length)
 
153
  void NWindowsSerialFileReader::SerializeFinal (void *Dest, long long Length)
154
154
  {
155
155
    nuxAssert (Dest);
156
156
 
157
157
    while (Length > 0)
158
158
    {
159
 
      t_int DataSize = Min<t_s64> (Length, m_BufferBase + m_BufferCount - m_FilePos);
 
159
      int DataSize = Min<long long> (Length, m_BufferBase + m_BufferCount - m_FilePos);
160
160
 
161
161
      if (DataSize == 0)
162
162
      {
163
163
        if (Length >= sBufferSize)
164
164
        {
165
 
          t_int Count = 0;
 
165
          int Count = 0;
166
166
          //GTotalBytesReadViaFileManager += Length;
167
167
          ReadFile (m_FileHandle, Dest, Length, (DWORD *) &Count, NULL);
168
168
 
178
178
        }
179
179
 
180
180
        Precache (m_FilePos, t_s32_max);
181
 
        DataSize = Min<t_s64> (Length, m_BufferBase + m_BufferCount - m_FilePos);
 
181
        DataSize = Min<long long> (Length, m_BufferBase + m_BufferCount - m_FilePos);
182
182
 
183
183
        if (DataSize <= 0)
184
184
        {
198
198
  }
199
199
//////////////////////////////////////////////////////////////////////////
200
200
// Choose the size so it is a power of 2. Example (size-1)= 11111111.
201
 
  const t_int  NWindowsSerialFileWriter::sBufferSize = 32;
 
201
  const int  NWindowsSerialFileWriter::sBufferSize = 32;
202
202
//NCriticalSection NWindowsSerialFileWriter::m_CriticalSection;
203
203
 
204
204
  NWindowsSerialFileWriter::NWindowsSerialFileWriter (HANDLE InHandle, LogOutputDevice &InError)
220
220
    m_FileHandle = NULL;
221
221
  }
222
222
 
223
 
  t_s64 NWindowsSerialFileWriter::Seek (t_s64 InPos, NSerializer::SeekPos seekpos)
 
223
  long long NWindowsSerialFileWriter::Seek (long long InPos, NSerializer::SeekPos seekpos)
224
224
  {
225
225
    NScopeLock Scope (&m_CriticalSection);
226
226
    nuxAssert (m_FileHandle);
245
245
    return filepos.QuadPart;
246
246
  }
247
247
 
248
 
  t_s64 NWindowsSerialFileWriter::Tell()
 
248
  long long NWindowsSerialFileWriter::Tell()
249
249
  {
250
250
    NScopeLock Scope (&m_CriticalSection);
251
251
    nuxAssert (m_FileHandle);
282
282
    return !m_ErrorCode;
283
283
  }
284
284
 
285
 
  t_s64 NWindowsSerialFileWriter::GetFileSize()
 
285
  long long NWindowsSerialFileWriter::GetFileSize()
286
286
  {
287
287
    nuxAssert (m_FileHandle);
288
288
 
289
289
    if (m_FileHandle == NULL)
290
290
      return -1;
291
291
 
292
 
    t_s64 Size = 0;
 
292
    long long Size = 0;
293
293
 
294
294
    if (::GetFileSizeEx (m_FileHandle, NUX_REINTERPRET_CAST (PLARGE_INTEGER, &Size) ) == 0)
295
295
    {
299
299
    return Size;
300
300
  }
301
301
 
302
 
  void NWindowsSerialFileWriter::SerializeFinal (void *V, t_s64 Length)
 
302
  void NWindowsSerialFileWriter::SerializeFinal (void *V, long long Length)
303
303
  {
304
304
    // This method is not re-entrant by itself. It relies on m_Buffer and other variables
305
305
    // that belong to this object. Therefore, it is not thread safe. We add a critical section
312
312
    NUX_RETURN_IF_NULL (m_FileHandle);
313
313
 
314
314
    m_Pos += Length;
315
 
    t_int FreeSpace;
 
315
    int FreeSpace;
316
316
 
317
317
    while (Length > (FreeSpace = sBufferSize - m_BufferCount) )
318
318
    {
347
347
    //GTotalBytesWrittenViaFileManager += m_BufferCount;
348
348
    if (m_BufferCount)
349
349
    {
350
 
      t_int Result = 0;
 
350
      int Result = 0;
351
351
 
352
352
      if (!WriteFile (m_FileHandle, m_Buffer, m_BufferCount, (DWORD *) &Result, NULL) )
353
353
      {
419
419
    Create          |= (Flags & NSerializer::NoOverWrite) ? CREATE_NEW /*fail if the file already exist*/ : CREATE_ALWAYS /*create the file if it does not exist*/;
420
420
    HANDLE Handle    = ::CreateFile (Filename, Access, SharedModeFlags, NULL, Create, FILE_ATTRIBUTE_NORMAL, NULL);
421
421
 
422
 
    t_int Pos = 0;
 
422
    int Pos = 0;
423
423
 
424
424
    if (Handle == INVALID_HANDLE_VALUE)
425
425
    {
454
454
  /*!
455
455
      @return Size of the File. Return -1 if an error occurs.
456
456
  */
457
 
  t_s64 NFileManagerWindows::FileSize (const TCHAR *Filename)
 
457
  long long NFileManagerWindows::FileSize (const TCHAR *Filename)
458
458
  {
459
459
    HANDLE Handle = ::CreateFile (Filename, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
460
460
 
475
475
      return -1;
476
476
    }
477
477
 
478
 
    t_s64 Size = 0;
 
478
    long long Size = 0;
479
479
 
480
480
    if (::GetFileSizeEx (Handle, NUX_REINTERPRET_CAST (PLARGE_INTEGER, &Size) ) == 0)
481
481
    {
613
613
  /*!
614
614
      @return TRUE is the file exist.
615
615
  */
616
 
  bool NFileManagerWindows::GetFileAttribute (const TCHAR *Filename, bool &isDirectory, bool &isReadOnly, bool &isHidden, t_s64 &Size)
 
616
  bool NFileManagerWindows::GetFileAttribute (const TCHAR *Filename, bool &isDirectory, bool &isReadOnly, bool &isHidden, long long &Size)
617
617
  {
618
618
    isDirectory = false;
619
619
    isReadOnly = false;
626
626
      isDirectory = ( (FileAttrData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
627
627
      isReadOnly = ( (FileAttrData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
628
628
      isHidden = ( (FileAttrData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
629
 
      Size = FileAttrData.nFileSizeLow | ( (t_s64) (FileAttrData.nFileSizeHigh) << 32);
 
629
      Size = FileAttrData.nFileSizeLow | ( (long long) (FileAttrData.nFileSizeHigh) << 32);
630
630
    }
631
631
    else
632
632
    {