File: prefmanager.d

package info (click to toggle)
projectl 1.001.dfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,720 kB
  • ctags: 5
  • sloc: xml: 57; makefile: 32
file content (108 lines) | stat: -rw-r--r-- 2,286 bytes parent folder | download | duplicates (3)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
module br.prefmanager;

private import std.stream;
private import util.record;
private import br.stage;
private import std.c.stdlib;
private import std.string;
private import std.conv;
private import std.file;

public class PrefManager{
	
	private:
	static const VERSION_NUM = 10;
	static const string PREF_FILE ="projectL.prf";
	PrefData _prefData;
	
	public this(){
		_prefData = new PrefData;
	}
	
	public void load() {
	    scope File fd = new File;
	    try {
	      int ver;
	      fd.open(prefDir() ~ "/" ~ PREF_FILE);
	      fd.read(ver);
	      if (ver != VERSION_NUM)
	        throw new Error("Wrong version num");
	      _prefData.load(fd);
	    } catch (Throwable e) {
	      _prefData.start();
	    } finally {
	      if (fd.isOpen())
	        fd.close();
	    }
 	}
	public void save(){
		scope File fd = new File;
	    fd.create(prefDir() ~ "/" ~ PREF_FILE);
	    fd.write(VERSION_NUM);
	    _prefData.save(fd);
	    fd.close();
	 }
	public PrefData prefData() {
    	return _prefData;
  	}

        static string prefDir() {
            const(char)* home = getenv("HOME");
            if (home is null)
                throw new Error("HOME environment variable not defined");
            string dir = to!string(home) ~ "/.projectl";
            try {
                mkdir(dir);
            } catch (FileException e) {
            }
            return dir;
        }
}

public class PrefData {
	private:
	int _fullScreen;
	int _nosound;
  	Record _record;
	public this(){
		_record = new Record(Stage.MAXSTAGE ,3);
		
	}
	
	public void start(){
		_fullScreen = 0;
		_nosound = 0;
		_record.start();
	}
	public void load(File fd) {
    _record.load(fd);
    fd.read(_nosound);
    fd.read(_fullScreen);
  }

  public void save(File fd) {
    _record.save(fd);
    fd.write(_nosound);
    fd.write(_fullScreen);
  }
  
  public void recordNoSound(bool ns){
  	if(ns)_nosound = 1;
	else _nosound = 0;
  }
  public void recordFullScreen(bool fs){
  	if(fs)_fullScreen = 1;
	else _fullScreen = 0;
  }
  public bool fullScreen(){
  	return _fullScreen != 0;

  }
  public bool nosound(){
  	return _nosound != 0;
  }
	
	public Record record(){
		return _record;
	}
}