-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathconfig.fs
69 lines (62 loc) · 1.99 KB
/
config.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module FVim.config
open FSharp.Data
open System.Runtime.InteropServices
open System.IO
open System
[<Literal>]
let sample_config = """
[
{
"workspace": [
{
"path": "C:\foo\bar",
"mainwin": {
"x": 1030,
"y": 200,
"w": 800,
"h": 600,
"state": "Normal",
"BackgroundComposition": "acrylic",
"CustomTitleBar": false
}
},
{
"path": "C:\foo\bar",
"mainwin": {
"x": 1030,
"y": 200,
"w": 800,
"h": 600,
"state": "Normal"
}
}
],
"Logging": {
"EchoOnConsole": false,
"LogToFile": ""
}
},
{}
]
"""
type ConfigObject = JsonProvider<sample_config, SampleIsList=true>
let configroot = if RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
then Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
else Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
let configdir = Path.Combine(configroot, "fvim")
let configfile = Path.Combine(configdir, "config.json")
try ignore <| Directory.CreateDirectory(configdir)
with _ -> ()
let load() =
try
let cfg = ConfigObject.Load configfile
cfg
with _ -> ConfigObject.Parse("{}")
let save (cfg: ConfigObject.Root) (x: int) (y: int) (w: int) (h: int) (state: string) (composition: string) (customTitleBar: bool) =
let dict = cfg.Workspace |> Array.map (fun ws -> (ws.Path, ws)) |> Map.ofArray
let cwd = Environment.CurrentDirectory |> Path.GetFullPath
let ws = ConfigObject.Workspace(cwd, ConfigObject.Mainwin(x, y, w, h, state, Some composition, Some customTitleBar))
let dict = dict.Add(cwd, ws)
let cfg = ConfigObject.Root(dict |> Map.toArray |> Array.map snd, cfg.Logging)
try File.WriteAllText(configfile, cfg.ToString())
with _ -> ()