OSDN Git Service

Merge pull request #1058 from sikabane-works/feature/enum-virtue
[hengbandforosx/hengbandosx.git] / src / main-win / main-win-file-utils.cpp
1 /*!
2  * @file main-win-file-utils.cpp
3  * @brief Windows版固有実装(ファイル関連処理)
4  */
5
6 #include "main-win/main-win-file-utils.h"
7 #include "main-win/main-win-define.h"
8 #include "main-win/main-win-windows.h"
9 #include "util/angband-files.h"
10
11 /*
12  * Check for existance of a file
13  */
14 bool check_file(concptr s)
15 {
16     char path[MAIN_WIN_MAX_PATH];
17     strcpy(path, s);
18     DWORD attrib = GetFileAttributesA(path);
19     if (attrib == INVALID_FILE_NAME)
20         return FALSE;
21     if (attrib & FILE_ATTRIBUTE_DIRECTORY)
22         return FALSE;
23
24     return TRUE;
25 }
26
27 /*
28  * Check for existance of a directory
29  */
30 bool check_dir(concptr s)
31 {
32     char path[MAIN_WIN_MAX_PATH];
33     strcpy(path, s);
34     int i = strlen(path);
35     if (i && (path[i - 1] == '\\'))
36         path[--i] = '\0';
37
38     DWORD attrib = GetFileAttributesA(path);
39     if (attrib == INVALID_FILE_NAME)
40         return FALSE;
41     if (!(attrib & FILE_ATTRIBUTE_DIRECTORY))
42         return FALSE;
43
44     return TRUE;
45 }
46
47 /*!
48  * @brief 候補リストを順に確認し、存在するファイルのパスを返す。
49  * @param dir ディレクトリ
50  * @param files ファイル名のリスト
51  * @return ファイルのパスを返す。候補リストのファイルすべて存在しない場合は空文字列を返す。
52  */
53 std::string find_any_file(concptr dir, std::initializer_list<concptr> files)
54 {
55     char path[MAIN_WIN_MAX_PATH];
56
57     for (concptr filename : files) {
58         path_build(path, MAIN_WIN_MAX_PATH, dir, filename);
59         if (check_file(path)) {
60             return std::string(path);
61         }
62     }
63
64     return std::string();
65 }