aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2017-03-01 07:40:53 -0700
committerSean Whitton <spwhitton@spwhitton.name>2017-03-01 07:40:53 -0700
commita4cde5b0ce1f16e844967918221a2d92aba6ecef (patch)
treebe7ba9849a4deeba9fee89218a536384724284d6
parente604888020626b0fbbd2fc9c0b0b64975e9ad6f3 (diff)
downloadsscan-a4cde5b0ce1f16e844967918221a2d92aba6ecef.tar.gz
start work to check scanimage's exit code
-rw-r--r--Main.hs30
1 files changed, 17 insertions, 13 deletions
diff --git a/Main.hs b/Main.hs
index 185a91f..92bcfd8 100644
--- a/Main.hs
+++ b/Main.hs
@@ -30,6 +30,7 @@ import Lens.Micro ((&), (.~), (^.))
import System.Directory (getHomeDirectory,
removeDirectoryRecursive, renamePath,
withCurrentDirectory)
+import System.Exit (ExitCode (..))
import System.FilePath ((<.>), (</>))
import System.IO (IOMode (WriteMode), hClose, openFile)
import System.IO.Temp (withSystemTempDirectory)
@@ -58,13 +59,14 @@ processScanSessDir st dir = withCurrentDirectory dir $ do
, std_err = UseHandle logH
}
-- 3. maybe ocrmypdf
- when (st^.stOCR) $ renamePath "temp.pdf" "temp2.pdf"
- >> createProcessWait_ "OCRmyPDF"
- (proc "ocrmypdf" ["-c", "-i", "-r", "temp2.pdf", "temp.pdf"])
- { std_in = NoStream
- , std_out = NoStream
- , std_err = UseHandle logH
- }
+ when (st^.stOCR) $ do
+ renamePath "temp.pdf" "temp2.pdf"
+ void $ createProcessWait_ "OCRmyPDF"
+ (proc "ocrmypdf" ["-c", "-i", "-r", "temp2.pdf", "temp.pdf"])
+ { std_in = NoStream
+ , std_out = NoStream
+ , std_err = UseHandle logH
+ }
-- 4. qpdf (ocrmypdf invokes qpdf but it doesn't use
-- --linearize, which shrinks the PDF, often substantially)
createProcessWait_ "qpdf" (proc "qpdf" ["--linearize", "temp.pdf"])
@@ -110,14 +112,16 @@ makeInitialState = do
scanPage :: St -> FilePath -> IO ()
scanPage st dir = do
outH <- openFile outF WriteMode
- -- TODO if scanimage exists non-zero, inform the user that we will
- -- abort the scan session, pause for them to read the output, and then
- -- abort the scan session
- createProcessWait_ "scanimage" (proc "scanimage" (scanimageArgs st))
+ exit <- createProcessWait_ "scanimage" (proc "scanimage" (scanimageArgs st))
{ std_in = NoStream
, std_out = UseHandle outH
, std_err = Inherit -- let the user see progress bar
}
+ case exit of
+ -- TODO inform the user that we will abort the scan session,
+ -- pause for them to read scanimage's error output, and then
+ -- abort the scan session
+ ExitFailure _ -> undefined
hClose outH
where
outF = dir </> "page" ++ (show $ getLatestPage st + 1) <.> "tiff"
@@ -168,7 +172,7 @@ main = makeInitialState >>= presentUI
-- | Create a process, wait for it to finish, don't close any
-- handles used by the CreateProcess record
-createProcessWait_ :: String -> CreateProcess -> IO ()
+createProcessWait_ :: String -> CreateProcess -> IO ExitCode
createProcessWait_ s c = do
(_, _, _, p) <- createProcess_ s c
- void $ waitForProcess p
+ waitForProcess p