CLI interface to medialist (fossil mirror)
修訂 | b9ad10af01ca9d1a3590bf0a634fdd5447138c23 (tree) |
---|---|
時間 | 2023-04-04 15:08:37 |
作者 | mio <stigma@disr...> |
Commiter | mio |
Change ml_open_list (nothrow) to call ml_open_list (throw).
Change mentions of version 0.2.0/0.4.0 to 0.4.0 to match medialist-cli.
FossilOrigin-Name: edaab5e4722276e835dc261bb380bd3ef5032450316cd30ee68b48bcd957675d
@@ -32,9 +32,9 @@ import std.string; | ||
32 | 32 | /// |
33 | 33 | /// Enumeration string containing the verison of MediaList. |
34 | 34 | /// |
35 | -/// Since: 0.2.0 | |
35 | +/// Since: 0.4.0 | |
36 | 36 | /// |
37 | -enum string MediaListVersion = "0.2.0-dev"; | |
37 | +enum string MediaListVersion = "0.4.0-dev"; | |
38 | 38 | |
39 | 39 | /// |
40 | 40 | /// Enumeration array of int containing the version of MediaList. |
@@ -45,9 +45,9 @@ enum string MediaListVersion = "0.2.0-dev"; | ||
45 | 45 | /// API. Patch versions represent compile-time fixes. Minor versions represent |
46 | 46 | /// all other changes. |
47 | 47 | /// |
48 | -/// Since: 0.2.0 | |
48 | +/// Since: 0.4.0 | |
49 | 49 | //// |
50 | -enum int[3] MediaListVersionA = [0, 2, 0]; | |
50 | +enum int[3] MediaListVersionA = [0, 4, 0]; | |
51 | 51 | |
52 | 52 | /// |
53 | 53 | /// The main structure for interacting with a list in `medialist`. |
@@ -380,70 +380,30 @@ MediaList* ml_open_list(string filePath) | ||
380 | 380 | /// |
381 | 381 | /// Returns: A GC-allocated MediaList structure. |
382 | 382 | /// |
383 | -/// Throws: | |
384 | -/// - ErrnoException if the file could not be opened, there was an | |
385 | -/// error writing to file, or if there was an error closing the | |
386 | -/// file. | |
387 | -/// | |
388 | 383 | MediaList* ml_open_list(string filePath, out MLError error) nothrow |
389 | 384 | { |
390 | 385 | import std.exception : ErrnoException; |
391 | 386 | import core.stdc.errno; |
392 | 387 | |
393 | - string listName = stripExtension(baseName(filePath)); | |
394 | - MediaList* ml = new MediaList(filePath, listName); | |
388 | + MediaList* list; | |
395 | 389 | |
396 | - if (false == exists(filePath)) | |
397 | - { | |
398 | - ml.isOpen = true; | |
399 | - scope (exit) | |
400 | - ml.isOpen = false; | |
401 | - | |
402 | - try | |
403 | - { | |
404 | - File f = File(filePath, "w+"); | |
405 | - | |
406 | - f.writeln("# This file is in the mTSV format."); | |
407 | - f.writeln("# For more information about this format,"); | |
408 | - f.writeln("# please view the website:"); | |
409 | - f.writeln("# http://yume-neru.neocities.org/p/mtsv.html"); | |
410 | - f.writeln("title\tprogress\tstatus\tstart_date\tend_date\tlast_updated"); | |
411 | - } | |
412 | - catch (ErrnoException ee) | |
413 | - { | |
414 | - static if (__VERSION__ < 2088L) | |
415 | - { | |
416 | - switch (errno) | |
417 | - { | |
418 | - case EACCES: | |
419 | - error = MLError.permissionError; | |
420 | - return null; | |
421 | - default: | |
422 | - error = MLError.unspecifiedError; | |
423 | - return null; | |
424 | - } | |
425 | - } | |
426 | - else | |
427 | - { | |
428 | - switch (ee.errno()) | |
429 | - { | |
430 | - case EACCES: | |
431 | - error = MLError.permissionError; | |
432 | - return null; | |
433 | - default: | |
434 | - error = MLError.unspecifiedError; | |
435 | - return null; | |
436 | - } | |
437 | - } | |
438 | - } | |
439 | - catch (Exception e) | |
390 | + try { | |
391 | + list = ml_open_list(filePath); | |
392 | + } catch (ErrnoException ee) { | |
393 | + switch (errno) | |
440 | 394 | { |
395 | + case EACCES: | |
396 | + error = MLError.permissionError; | |
397 | + break; | |
398 | + default: | |
441 | 399 | error = MLError.unspecifiedError; |
442 | - return null; | |
400 | + break; | |
443 | 401 | } |
402 | + } catch (Exception e) { | |
403 | + error = MLError.unspecifiedError; | |
444 | 404 | } |
445 | 405 | |
446 | - return ml; | |
406 | + return list; | |
447 | 407 | } |
448 | 408 | |
449 | 409 | /// |
@@ -1367,7 +1327,7 @@ private void _ml_delete(MediaList* list, string[] args) | ||
1367 | 1327 | throw new MLException(MLError.fileAlreadyOpen); |
1368 | 1328 | |
1369 | 1329 | if (0 == args.length) { |
1370 | - // NOTE: This will be removed in a version after 0.2.0. | |
1330 | + // NOTE: This will be removed in a version after 0.4.0. | |
1371 | 1331 | remove(list.filePath); |
1372 | 1332 | return; |
1373 | 1333 | } |