OSDN Git Service

Fix build errors
[winmerge-jp/winmerge-jp.git] / Src / DirItem.cpp
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /** 
3  * @file  DirItem.cpp
4  *
5  * @brief Implementation for DirItem routines
6  */
7
8 #include "pch.h"
9 #include "DirItem.h"
10 #include "UnicodeString.h"
11 #include "paths.h"
12 #include "TFile.h"
13 #include "DebugNew.h"
14
15 /**
16  * @brief Set filename and path for the item.
17  * @param [in] fullpath Full path to file to set to item.
18  */
19 void DirItem::SetFile(const String &fullPath)
20 {
21         String ext, filename2, path2;
22         paths::SplitFilename(fullPath, &path2, &filename2, &ext);
23         filename2 += _T(".");
24         filename2 += ext;
25         filename = filename2;
26         path = path2;
27 }
28
29 /**
30  * @brief Get the full path of the item.
31  * @return fullpath
32  */
33 String DirItem::GetFile() const
34 {
35         return paths::ConcatPath(path.get(), filename.get());
36 }
37
38 /**
39  * @brief Update fileinfo from given file.
40  * This function updates file's information from given item. Function
41  * does not set filename and path.
42  * @param [in] sFilePath Full path to file/directory to update
43  * @return true if information was updated (item was found).
44  */
45 bool DirItem::Update(const String &sFilePath)
46 {
47         bool retVal = false;
48
49         size = DirItem::FILE_SIZE_NONE;
50         flags.reset();
51         mtime = 0;
52
53         if (!sFilePath.empty())
54         {
55                 try
56                 {
57                         TFile file(sFilePath);
58
59                         mtime = file.getLastModified();
60                         // There can be files without modification date.
61                         // Then we must use creation date. Of course we assume
62                         // creation date then exists...
63                         if (mtime == 0)
64                                 mtime = file.created();
65
66                         // No size for directory ( size remains as -1)
67                         if (!file.isDirectory())
68                                 size = file.getSize();
69
70                         flags.attributes = GetFileAttributes(file.wpath().c_str());
71
72                         retVal = true;
73                 }
74                 catch (...)
75                 {
76                 }
77         }
78         return retVal;
79 }
80
81 /**
82  * @brief Clears FileInfo data.
83  */
84 /*void DirItem::Clear()
85 {
86         ClearPartial();
87         filename.erase();
88         path.erase();
89 }*/
90
91 /**
92  * @brief Clears FileInfo data except path/filename.
93  */
94 void DirItem::ClearPartial()
95 {
96         ctime = 0;
97         mtime = 0;
98         size = DirItem::FILE_SIZE_NONE;
99         flags.reset();
100 }