PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/win32/shellext/Direntry.cpp

https://bitbucket.org/tortoisehg/hgtk/
C++ | 71 lines | 42 code | 14 blank | 15 comment | 7 complexity | 24fee94a2cbea06f61323a2590d4b181 MD5 | raw file
 1
 2// Copyright (C) 2009 Benjamin Pollack
 3// Copyright (C) 2009 Adrian Buehlmann
 4//
 5// This program is free software: you can redistribute it and/or modify
 6// it under the terms of the GNU General Public License as published by
 7// the Free Software Foundation, either version 2 of the License, or
 8// (at your option) any later version.
 9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18#include "stdafx.h"
19
20#include "Direntry.h"
21#include "Winstat.h"
22
23
24int Direntry::read(FILE* f, std::vector<char>& relpath)
25{
26    if (fread(&state, sizeof(state), 1, f) != 1)
27        return 0;
28
29    unsigned length = 0;
30
31    fread(&mode, sizeof(mode), 1, f);
32    fread(&size, sizeof(size), 1, f);
33    fread(&mtime, sizeof(mtime), 1, f);
34    fread(&length, sizeof(length), 1, f);
35
36    mode = ntohl(mode);
37    size = ntohl(size);
38    mtime = ntohl(mtime);
39    length = ntohl(length);
40
41    relpath.resize(length + 1, 0);
42    fread(&relpath[0], sizeof(char), length, f);
43    relpath[length] = 0;
44
45    ::CharLowerBuff(&relpath[0], length);
46
47    return 1;
48}
49
50
51char Direntry::status(const Winstat& stat) const
52{
53    switch (this->state)
54    {
55    case 'n':
56        if (this->size != (unsigned)stat.size)
57            return 'M'; // modified
58        if (this->mtime == (unsigned)stat.mtime)
59            return 'C'; // clean
60        return 'P'; // must peek into file contents
61    case 'm':
62        return 'M';
63    case 'r':
64        return 'R';
65    case 'a':
66        return 'A';
67    default:
68        return '?';
69    }
70}
71