Permalink
Browse files

Fixed path processing on Windows (and settings path moved to AppData)

  • Loading branch information...
1 parent 29b75a2 commit 86302b1cf3c762e6c833591f0b44f66f2c6dedfd unknown committed May 14, 2012
@@ -13,9 +13,9 @@ import qualified System.Win32 as Win32
import Control.Applicative
import Control.Monad
import Data.List.Split (splitOn)
-import System.FilePath ((</>), isAbsolute, takeDirectory, pathSeparator)
+import System.FilePath ((</>), isDrive, isAbsolute, takeDirectory, pathSeparator, normalise)
import System.Directory (getCurrentDirectory)
-import System.Posix.Files (readSymbolicLink)
+import System.PosixCompat.Files (readSymbolicLink)
-- | Removes `/./` `//` and `/../` sequences from path,
@@ -33,7 +33,7 @@ canonicalizePath path = do
absPath <- makeAbsolute path
foldM (\x y -> expandSym $ combinePath x y) "/" $ splitPath absPath
#else
- Win32.getFullPathName . normalise
+ Win32.getFullPathName . normalise $ path
#endif
-- | Dereferences symbolic links until regular
@@ -59,7 +59,9 @@ makeAbsolute f
combinePath :: FilePath -> String -> FilePath
combinePath x "." = x
combinePath x ".." = takeDirectory x
-combinePath x y = x </> y
+combinePath x y
+ | isDrive x = (x ++ [pathSeparator]) </> y -- "C:" </> "bin" = "C:bin"
+ | otherwise = x </> y
-- | Splits path into parts by path separator
splitPath :: FilePath -> [String]
@@ -6,7 +6,7 @@ module System.FriendlyPath
import Control.Applicative
import System.FilePath
-import System.Posix.User (getUserEntryForName, homeDirectory)
+import System.PosixCompat.User (getUserEntryForName, homeDirectory)
import System.CanonicalizePath
import System.Directory hiding (canonicalizePath)
@@ -236,18 +236,33 @@ nilKeymap = choice [
"You should however create your own ~/.yi/yi.hs file: ",
"You can type 'c', 'e' or 'v' now to create and edit it using a temporary cua, emacs or vim keymap."]
openCfg km kmName = write $ do
- dataDir <- io $ getDataDir
+ dataDir <- io getDataDir
let exampleCfg = dataDir </> "example-configs" </> kmName
- homeDir <- io $ getHomeDirectory
- let cfgDir = homeDir </> ".yi"
- cfgFile = cfgDir </> "yi.hs"
- cfgExists <- io $ doesFileExist cfgFile
- -- io $ print cfgExists
- io $ createDirectoryIfMissing True cfgDir -- so that the file can be saved.
+ homeDir <- io getHomeDirectory
+ cfgDir <- io $ getAppUserDataDirectory "yi"
+ let cfgFile = cfgDir </> "yi.hs"
+ cfgExists <- io $ doesFileExist cfgDir
+ io $ createDirectoryIfMissing True cfgDir -- so that the file can be saved
discard $ editFile cfgFile -- load config file
-- locally override the keymap to the user choice
- withBuffer $ modifyMode (\m -> m {modeKeymap = const km})
+ withBuffer $ modifyMode (\m -> m { modeKeymap = const km })
when (not cfgExists) $ do
- -- file did not exist, load a reasonable default
- defCfg <- io $ readFile exampleCfg
- withBuffer $ insertN defCfg
+ -- file did not exist, load a reasonable default
+ defCfg <- io $ readFile exampleCfg
+ withBuffer $ insertN defCfg
+-- openCfg km kmName = write $ do
+-- dataDir <- io $ getDataDir
+-- let exampleCfg = dataDir </> "example-configs" </> kmName
+-- homeDir <- io $ getHomeDirectory
+-- let cfgDir = homeDir </> ".yi"
+-- cfgFile = cfgDir </> "yi.hs"
+-- cfgExists <- io $ doesFileExist cfgFile
+-- -- io $ print cfgExists
+-- io $ createDirectoryIfMissing True cfgDir -- so that the file can be saved.
+-- discard $ editFile cfgFile -- load config file
+-- -- locally override the keymap to the user choice
+-- withBuffer $ modifyMode (\m -> m {modeKeymap = const km})
+-- when (not cfgExists) $ do
+-- -- file did not exist, load a reasonable default
+-- defCfg <- io $ readFile exampleCfg
+-- withBuffer $ insertN defCfg
View
@@ -28,15 +28,15 @@ flag cocoa
Description: "Build with Cocoa frontend"
flag pango
- Default: False
+ Default: True
Description: "Build with Pango frontend"
flag vte
Default: False
Description: "Build with Vte frontend"
flag vty
- Default: True
+ Default: False
Description: "Build with Vty frontend"
flag scion
@@ -243,6 +243,10 @@ library
build-depends:
unix
+ if os(windows)
+ build-depends:
+ Win32
+
include-dirs: src/library/Yi/Lexer
if flag(testing)

0 comments on commit 86302b1

Please sign in to comment.