Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

shellext: new Winstat.h and .cpp

Changeset 7051753b84f2

Parent 5cda5fda8327

by Adrian Buehlmann

Changes to 7 files · Browse files at 7051753b84f2 Showing diff from parent 5cda5fda8327 Diff from another changeset...

 
18
19
20
 
21
22
23
 
174
175
176
177
 
178
179
180
 
183
184
185
186
 
187
188
189
 
18
19
20
21
22
23
24
 
175
176
177
 
178
179
180
181
 
184
185
186
 
187
188
189
190
@@ -18,6 +18,7 @@
 #include "stdafx.h"    #include "Directory.h" +#include "Winstat.h"      Directory::~Directory() @@ -174,7 +175,7 @@
  added = true;   }   - thg_stat stat; + Winstat stat;   const std::string hrs = hgroot + '\\';   for (FilesT::iterator i = files_.begin(); i != files_.end(); ++i)   { @@ -183,7 +184,7 @@
    std::string p = hrs + path(i->name);   - if (0 != lstat(p.c_str(), stat)) + if (0 != stat.lstat(p.c_str()))   return 'M'; // file is missing, report dir as modified     char s = i->status(stat);
 
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
43
44
45
 
67
68
69
70
 
71
72
73
 
18
19
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
22
23
24
 
46
47
48
 
49
50
51
52
@@ -18,28 +18,7 @@
 #include "stdafx.h"    #include "Direntry.h" - - -int lstat(const char* file, thg_stat& rstat) -{ - const __int64 days_between_epochs = 134774L; /* days between 1.1.1601 and 1.1.1970 */ - const __int64 secs_between_epochs = (__int64)days_between_epochs * 86400L; - const __int64 divisor = 10000000L; - - WIN32_FIND_DATAA data; - HANDLE hfind; - - hfind = FindFirstFileA(file, &data); - if (hfind == INVALID_HANDLE_VALUE) - return -1; - FindClose(hfind); - - rstat.mtime = *(__int64*)&data.ftLastWriteTime / divisor - secs_between_epochs; - rstat.size = (data.nFileSizeHigh << sizeof(data.nFileSizeHigh)) | data.nFileSizeLow; - rstat.isdir = (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; - - return 0; -} +#include "Winstat.h"      int Direntry::read(FILE* f, std::vector<char>& relpath) @@ -67,7 +46,7 @@
 }     -char Direntry::status(const thg_stat& stat) const +char Direntry::status(const Winstat& stat) const  {   switch (this->state)   {
 
20
21
22
23
24
25
26
27
28
29
30
31
32
 
33
34
35
 
42
43
44
45
 
46
47
48
 
20
21
22
 
 
 
 
 
 
 
 
 
 
23
24
25
26
 
33
34
35
 
36
37
38
39
@@ -20,16 +20,7 @@
   #include <vector>   - -struct thg_stat -{ - unsigned size; - unsigned mtime; - bool isdir; -}; - -int lstat(const char* file, thg_stat& rstat); - +class Winstat;    class Direntry  { @@ -42,7 +33,7 @@
  std::string name;     int read(FILE* f, std::vector<char>& relpath); - char status(const thg_stat& stat) const; + char status(const Winstat& stat) const;    private:   static uint32_t ntohl(uint32_t x)
 
8
9
10
 
11
12
13
 
8
9
10
11
12
13
14
@@ -8,6 +8,7 @@
  PipeUtils.o \   ShellUtils2.o \   StringUtils.o \ + Winstat.o \   Direntry.o \   Directory.o \   dirstate.o
Change 1 of 1 Show Entire File tortoise/​shellext/​Winstat.cpp Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@@ -0,0 +1,41 @@
+ +// Copyright (C) 2009 Benjamin Pollack +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +#include "stdafx.h" + +#include "Winstat.h" + + +int Winstat::lstat(const char* file) +{ + const __int64 days_between_epochs = 134774L; /* days between 1.1.1601 and 1.1.1970 */ + const __int64 secs_between_epochs = (__int64)days_between_epochs * 86400L; + const __int64 divisor = 10000000L; + + WIN32_FIND_DATAA data; + HANDLE hfind; + + hfind = FindFirstFileA(file, &data); + if (hfind == INVALID_HANDLE_VALUE) + return -1; + FindClose(hfind); + + this->mtime = *(__int64*)&data.ftLastWriteTime / divisor - secs_between_epochs; + this->size = (data.nFileSizeHigh << sizeof(data.nFileSizeHigh)) | data.nFileSizeLow; + this->isdir = (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; + + return 0; +}
Change 1 of 1 Show Entire File tortoise/​shellext/​Winstat.h Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@@ -0,0 +1,30 @@
+ +// Copyright (C) 2009 Benjamin Pollack +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +#ifndef WINSTAT_H +#define WINSTAT_H + +class Winstat +{ +public: + unsigned size; + unsigned mtime; + bool isdir; + + int lstat(const char* file); +}; + +#endif
 
19
20
21
 
22
23
24
 
143
144
145
146
 
147
148
149
150
151
152
 
153
154
155
 
234
235
236
237
238
 
 
239
240
241
 
19
20
21
22
23
24
25
 
144
145
146
 
147
148
149
150
151
152
 
153
154
155
156
 
235
236
237
 
 
238
239
240
241
242
@@ -19,6 +19,7 @@
 #include "dirstate.h"  #include "Directory.h"  #include "TortoiseUtils.h" +#include "Winstat.h"    #include <shlwapi.h>   @@ -143,13 +144,13 @@
    std::string path = hgroot + "\\.hg\\dirstate";   - thg_stat stat; + Winstat stat;     bool stat_done = false;     if (isnew || (tc - iter->tickcount) > 500)   { - if (0 != lstat(path.c_str(), stat)) + if (0 != stat.lstat(path.c_str()))   {   TDEBUG_TRACE("Dirstatecache::get: lstat(" << path <<") failed");   return 0; @@ -234,8 +235,8 @@
  if (!e)   return 0;   - thg_stat stat; - if (0 != lstat(path.c_str(), stat)) { + Winstat stat; + if (0 != stat.lstat(path.c_str())) {   TDEBUG_TRACE("HgQueryDirstate: lstat(" << path << ") failed");   return 0;   }