A CLI tool for downloading from pixiv.net
Révision | 1338821d76a4a01f227cbfe0c4720d077a77a2e4 (tree) |
---|---|
l'heure | 2023-06-17 12:11:16 |
Auteur | mio <stigma@disr...> |
Commiter | mio |
Update pixiv_down to use new directories API
@@ -837,29 +837,28 @@ loadConfig() | ||
837 | 837 | { |
838 | 838 | Config config; |
839 | 839 | string sessionid; |
840 | - DirEntry homeDir = open(Directory.home); | |
841 | - DirEntry configDir = open(Directory.config); | |
842 | - DirEntry dataDir = open(Directory.data); | |
843 | 840 | |
844 | - string configDirPath = buildPath(configDir, "pixiv_down"); | |
845 | - if (exists(configDirPath)) { | |
846 | - string configFilePath = buildPath(configDirPath, "settings.conf"); | |
841 | + ProjectDirectories dirs = getProjectDirectories(null, "YumeNeru Software", | |
842 | + "pixiv_down"); | |
843 | + UserDirectories userDirs = getUserDirectories(); | |
844 | + | |
845 | + if (exists(dirs.configDir)) { | |
846 | + string configFilePath = buildPath(dirs.configDir, "settings.conf"); | |
847 | 847 | if (exists(configFilePath)) { |
848 | 848 | scope parser = new ConfigParser(); |
849 | 849 | parser.read(configFilePath); |
850 | 850 | config.baseFolder = parser.get("output", "base_folder", |
851 | - buildPath(homeDir, "Pictures")); | |
851 | + userDirs.pictureDir); | |
852 | 852 | } |
853 | 853 | } else { |
854 | 854 | // Set default values |
855 | - config.baseFolder = buildPath(homeDir, "Pictures"); | |
855 | + config.baseFolder = userDirs.pictureDir; | |
856 | 856 | } |
857 | 857 | |
858 | - string dataDirPath = buildPath(dataDir, "pixiv_down"); | |
859 | - string idFilePath = buildPath(dataDirPath, ".phpsessid"); | |
858 | + string idFilePath = buildPath(dirs.dataDir, ".phpsessid"); | |
860 | 859 | |
861 | - if (!exists(dataDirPath)) { | |
862 | - mkdirRecurse(dataDirPath); | |
860 | + if (!exists(dirs.dataDir)) { | |
861 | + mkdirRecurse(dirs.dataDir); | |
863 | 862 | sessionid = askForSessionID(); |
864 | 863 | storeSessionID(sessionid, idFilePath); |
865 | 864 | } else { |
@@ -11,6 +11,9 @@ | ||
11 | 11 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
12 | 12 | */ |
13 | 13 | |
14 | +/// NOTE: pixiv_down uses a *slightly* modified version: it removes all | |
15 | +/// deprecations so no warnings are printed when compiling. | |
16 | + | |
14 | 17 | /** |
15 | 18 | * This module provides quick & easy access to the common directories |
16 | 19 | * for each operating system. Currently, only POSIX (XDG Base Directory |
@@ -65,26 +68,6 @@ | ||
65 | 68 | */ |
66 | 69 | module directories; |
67 | 70 | |
68 | -import std.file : DirEntry; | |
69 | - | |
70 | -/// | |
71 | -/// Deprecated: Use the new `getBaseDirectories`, `getProjectDirectories`, | |
72 | -/// and `getUserDirectories` functions. This will be removed | |
73 | -/// in version 0.3.0. | |
74 | -/// | |
75 | -deprecated("Use new get{Base,Project,User}Directories functions (remove 0.3.0)") | |
76 | -public enum Directory | |
77 | -{ | |
78 | - home, | |
79 | - data, | |
80 | - config, | |
81 | - state, | |
82 | - // dataDirs, /* XDG */ | |
83 | - // configDirs, /* XDG */ | |
84 | - cache, | |
85 | - runtime, | |
86 | -} | |
87 | - | |
88 | 71 | /// |
89 | 72 | /// Provides paths of user-invisible standard directories, following the |
90 | 73 | /// conventions of the operating system the library is running on. |
@@ -1138,104 +1121,8 @@ unittest | ||
1138 | 1121 | writeln(userDirs); |
1139 | 1122 | } |
1140 | 1123 | |
1141 | -/++ | |
1142 | - Return a DirEntry pointing to `dt`. | |
1143 | - | |
1144 | - If the folder couldn't be found, an empty DirEntry is returned. | |
1145 | - | |
1146 | - Deprecated: Use the new `getBaseDirectories`, `getProjectDirectories`, | |
1147 | - and `getUserDirectories` functions. This will be removed | |
1148 | - in version 0.3.0. | |
1149 | - | |
1150 | - Examples: | |
1151 | - ---- | |
1152 | - import directories; | |
1153 | - import std.stdio; | |
1154 | - | |
1155 | - int main() | |
1156 | - { | |
1157 | - DirEntry userConfDir = open(Directory.config); | |
1158 | - /* Handle error */ | |
1159 | - if (0 == userConfDir.name.length) | |
1160 | - { | |
1161 | - stderr.writeln("Failed to find user config directory."); | |
1162 | - return 1; | |
1163 | - } | |
1164 | - writefln("User config directory is %s", userConfDir.name); | |
1165 | - return 0; | |
1166 | - } | |
1167 | - ---- | |
1168 | -+/ | |
1169 | -deprecated("Use new get{Base,Project,User}Directories functions (remove 0.3.0)") | |
1170 | -public DirEntry open(Directory dt) nothrow// @safe | |
1171 | -{ | |
1172 | - /* | |
1173 | - * The Posix version covers a few operating systems, if your uses an | |
1174 | - * an alternative to XDG, let me know. | |
1175 | - */ | |
1176 | - version (Posix) enum supported = true; | |
1177 | - else version (Windows) enum supported = true; | |
1178 | - else enum supported = false; | |
1179 | - | |
1180 | - static if (false == supported) { | |
1181 | - static assert(0, "Unsupported platform."); | |
1182 | - } | |
1183 | - | |
1184 | - immutable string path = getPath(dt); | |
1185 | - if (path is null) return DirEntry(); | |
1186 | - try { | |
1187 | - return DirEntry(path); | |
1188 | - } catch (Exception e) { | |
1189 | - return DirEntry(); | |
1190 | - } | |
1191 | -} | |
1192 | - | |
1193 | -/// | |
1194 | -unittest | |
1195 | -{ | |
1196 | - import std.conv : to; | |
1197 | - import std.stdio : stderr; | |
1198 | - | |
1199 | - DirEntry emptyDir; | |
1200 | - | |
1201 | - foreach(dir; Directory.min..Directory.max) | |
1202 | - { | |
1203 | - string dirAsString = to!string(dir); | |
1204 | - DirEntry dirEntry = open(dir); | |
1205 | - version (Windows) | |
1206 | - { | |
1207 | - // Neither of these directories are supported on Windows. | |
1208 | - if (dir == Directory.state || dir == Directory.runtime) | |
1209 | - continue; | |
1210 | - } | |
1211 | - assert(emptyDir != dirEntry, "Failed to open(Directory." ~ dirAsString ~ ")"); | |
1212 | - stderr.writefln("Successfully opened Directory.%s: %s", dirAsString, dirEntry.name()); | |
1213 | - } | |
1214 | -} | |
1215 | - | |
1216 | 1124 | private: |
1217 | 1125 | |
1218 | -immutable(string) getPath(in Directory dt) nothrow @safe | |
1219 | -{ | |
1220 | - switch (dt) | |
1221 | - { | |
1222 | - case Directory.home: | |
1223 | - return home(); | |
1224 | - case Directory.data: | |
1225 | - return data(); | |
1226 | - case Directory.config: | |
1227 | - return config(); | |
1228 | - case Directory.cache: | |
1229 | - return cache(); | |
1230 | - case Directory.state: | |
1231 | - return state(); | |
1232 | - case Directory.runtime: | |
1233 | - return runtime(); | |
1234 | - default: | |
1235 | - assert(false, "Unsupported Directory"); | |
1236 | - } | |
1237 | -} | |
1238 | - | |
1239 | 1126 | immutable(string) home() nothrow @trusted |
1240 | 1127 | { |
1241 | 1128 | version (Posix) { |