A CLI tool for downloading from pixiv.net
修訂 | 58bc3c1acfa3a165d99cb0c4775eebefaace310a (tree) |
---|---|
時間 | 2023-06-17 11:04:53 |
作者 | mio <stigma@disr...> |
Commiter | mio |
Move loading of GraphicsMagick out of main
@@ -768,6 +768,73 @@ displayArtistHelp(string programName) | ||
768 | 768 | // Don't compile in |main| when building unittests. |
769 | 769 | version(unittest) {} else: |
770 | 770 | |
771 | +version(GMagick_Dynamic) | |
772 | +{ | |
773 | + | |
774 | +/// | |
775 | +/// Load the GraphicsMagick library. | |
776 | +/// | |
777 | +bool | |
778 | +loadLibGM(string programName) | |
779 | +{ | |
780 | + import graphicsmagick_c.config; | |
781 | + | |
782 | + bool success; | |
783 | + void* libgm; | |
784 | + | |
785 | + success = loadGraphicsMagick(libgm); | |
786 | + if (null !is libgm) { | |
787 | + stderr.writefln("%s: Failed to find the GraphicsMagick library.", | |
788 | + programName); | |
789 | + | |
790 | +version(appimage) { | |
791 | + stderr.writeln("\tThis shouldn't normally happen in an AppImage."); | |
792 | + stderr.writefln("\tPlease visit %s\nand let me know.", | |
793 | + "https://codeberg.org/supercell/pixiv_down/issues"); | |
794 | +} else version(linux) { | |
795 | + stderr.writeln("\tPlease make sure GraphicsMagick is installed."); | |
796 | + stderr.writeln("\tYou should be able to determine this by running " ~ | |
797 | + "`gm version` in your terminal."); | |
798 | + stderr.writefln("\tIf it is installed, please let me know at %s", | |
799 | + "https://codeberg.org/supercell/pixiv_down/issues"); | |
800 | +} else { | |
801 | + stderr.writeln("\tpixiv_down hasn't been tested on your OS."); | |
802 | + stderr.writefln("\tVisit %s and let me know the details!", | |
803 | + "https://codeberg.org/supercell/pixiv_down/issues"); | |
804 | +} | |
805 | + return false; | |
806 | + } // if (null is libgm) | |
807 | + | |
808 | + if (false == success) { | |
809 | + stderr.writefln("%s: There were some issues loading GraphicsMagick.", | |
810 | + programName); | |
811 | + stderr.writeln( | |
812 | + "\tIt's unlikely that there will be any issues running pixiv_down,\n" ~ | |
813 | + "\tbut please include the above ERROR messages when reporting\n" ~ | |
814 | + "\tany issues."); | |
815 | + } | |
816 | + | |
817 | + return success; | |
818 | +} | |
819 | + | |
820 | +} // version(GMagick_Dynamic) | |
821 | + | |
822 | +/// | |
823 | +/// Print GraphicsMagick version information to the pixiv_down log file. | |
824 | +/// | |
825 | +void | |
826 | +logLibGMVersion() | |
827 | +{ | |
828 | + import std.string : fromStringz; | |
829 | + import graphicsmagick_c.magick.version_ : GetMagickVersion, | |
830 | + MagickLibVersionText, MagickQuantumDepth; | |
831 | + | |
832 | + log.infof("GraphicsMagick Version D: %s", | |
833 | + fromStringz(GetMagickVersion(null))); | |
834 | + log.infof("GraphicsMagick Version S: %s", MagickLibVersionText); | |
835 | + log.infof("GraphicsMagick Depth S: %s", MagickQuantumDepth); | |
836 | +} | |
837 | + | |
771 | 838 | int |
772 | 839 | main(string[] args) |
773 | 840 | { |
@@ -823,58 +890,13 @@ version(appimage) { | ||
823 | 890 | log = new Logger("pixiv_down.log"); |
824 | 891 | |
825 | 892 | version (GMagick_Dynamic) { |
826 | - { | |
827 | - // This is the default build option, but I don't want | |
828 | - // it to cause problems if people try to build static. | |
829 | - | |
830 | - import graphicsmagick_c.config; | |
831 | - | |
832 | - void *libgm; | |
833 | - | |
834 | - bool success = loadGraphicsMagick(libgm); | |
835 | - if (null is libgm) { | |
836 | - stderr.writefln("%s: Failed to find the GraphicsMagick library.", | |
837 | - args[0]); | |
838 | - | |
839 | -version(appimage) { | |
840 | - stderr.writeln("This shouldn't normally happen in an AppImage."); | |
841 | - // NOTE(mio): Should have some other place that doesn't require | |
842 | - // registration... | |
843 | - stderr.writefln("Please visit %s\nand let me know.", | |
844 | - "https://codeberg.org/supercell/pixiv_down/issues"); | |
845 | -} else version(Linux) { | |
846 | - stderr.writeln("Please make sure GraphicsMagick is installed."); | |
847 | - stderr.writefln("If it is installed, please let me know at\n%s", | |
848 | - "https://codeberg.org/supercell/pixiv_down/issues"); | |
849 | -} else { | |
850 | - stderr.writeln("pixiv_down hasn't been tested on your OS."); | |
851 | - stderr.writefln("Visit %s and let me know the details!", | |
852 | - "https://codeberg.org/supercell/pixiv_down/issues"); | |
893 | + bool loadedGM = loadLibGM(args[0]); | |
894 | + if (!loadedGM) { | |
895 | + return 1; | |
896 | + } | |
853 | 897 | } |
854 | - } // if (null is libgm) | |
855 | - | |
856 | - if (false == success) { | |
857 | - stderr.writeln("There were some issues loading GraphicsMagick."); | |
858 | - stderr.writeln("It's unlikely that there will be any issues, but" ~ | |
859 | - " please include the above when reporting issues"); | |
860 | - } | |
861 | 898 | |
862 | - } // end of scope | |
863 | -} // GMagick_Dynamic | |
864 | - | |
865 | - { | |
866 | - /* | |
867 | - * Log Configuration Settings. | |
868 | - */ | |
869 | - import graphicsmagick_c.magick.version_ : GetMagickVersion, | |
870 | - MagickQuantumDepth, MagickLibVersionText; | |
871 | - import std.string : fromStringz; | |
872 | - | |
873 | - log.infof("GraphicsMagick Version D: %s", | |
874 | - GetMagickVersion(null).fromStringz); | |
875 | - log.infof("GraphicsMagick Version S: %s", MagickLibVersionText); | |
876 | - log.infof("GraphicsMagick Depth S: %s", MagickQuantumDepth); | |
877 | - } | |
899 | + logLibGMVersion(); | |
878 | 900 | |
879 | 901 | Config config; |
880 | 902 | DirEntry homeDir = open(Directory.home); |