module EndOfExe where
import qualified System.Directory as D (findExecutable)
import Data.Maybe (isJust)
import System.IO.Unsafe (unsafePerformIO)
endOfExecutable :: String -> IO (Maybe String)
endOfExecutable ys = do
xs <- D.findExecutable ys
if isJust xs
then return $ fmap (ys ++) (Just "")
else do
zs <- D.findExecutable (ys ++ ".exe")
if isJust zs
then return $ fmap (ys ++) (Just ".exe")
else error ("Please, install the executable " ++ ys ++ " into the directory in the PATH variable!")
showE :: String -> Maybe String
showE xs | null xs = error "No executable specified!"
| otherwise = let r = unsafePerformIO . endOfExecutable $ xs in
if isJust r
then r
else Nothing