PageRenderTime 40ms CodeModel.GetById 19ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/core/system.d

http://github.com/wilkie/djehuty
D | 135 lines | 88 code | 27 blank | 20 comment | 1 complexity | 76b1120ea8407c3fdba66e8ca34e2f27 MD5 | raw file
  1/*
  2 * system.d
  3 *
  4 * This module implements a class that can be used to query information
  5 * about the system.
  6 *
  7 */
  8
  9module core.system;
 10
 11import scaffold.system;
 12import scaffold.directory;
 13import scaffold.time;
 14
 15import core.locale : LocaleId;
 16import core.time;
 17import core.timezone;
 18
 19import io.directory;
 20import io.console;
 21
 22// Description: This class gives the developer a means to query common parameters about devices and configurations of the system.
 23class System {
 24	static:
 25	public:
 26
 27	class Displays {
 28		static:
 29		public:
 30
 31		uint count() {
 32			return SystemGetDisplayCount();
 33		}
 34
 35		uint primary() {
 36			return SystemGetPrimaryDisplay();
 37		}
 38
 39		int width(uint index) {
 40			return SystemGetDisplayWidth(index);
 41		}
 42
 43		int height(uint index) {
 44			return SystemGetDisplayHeight(index);
 45		}
 46	}
 47
 48	class Display {
 49		static:
 50		public:
 51
 52		int width() {
 53			return SystemGetDisplayWidth(Displays.primary);
 54		}
 55
 56		int height() {
 57			return SystemGetDisplayHeight(Displays.primary);
 58		}
 59	}
 60
 61	class Memory {
 62		static:
 63		public:
 64
 65		ulong total() {
 66			return SystemGetTotalMemory();
 67		}
 68
 69		ulong available() {
 70			return SystemGetAvailableMemory();
 71		}
 72	}
 73
 74	class FileSystem {
 75		static:
 76		public:
 77
 78		// Description: This function will return the Directory representing the current directory.
 79		// Returns: The Directory representing the working directory.
 80		Directory currentDir() {
 81			return Directory.open(DirectoryGetCWD());
 82		}
 83
 84		// Description: This function will return the Directory representing the directory the executable is located in. It should not be relied on completely, as this information can be incorrect or non-existent.
 85		// Returns: The Directory representing the executable location.
 86		Directory applicationDir() {
 87			return Directory.open(DirectoryGetApp());
 88		}
 89
 90		// Description: This function will return the Directory representing the system's temporary files directory. Persistance is not guaranteed.
 91		// Returns: The Directory representing the temp location.
 92		Directory tempDir() {
 93			Directory retdir = Directory.open(DirectoryGetTempData());
 94			if (retdir is null) {
 95				retdir = new Directory(DirectoryGetTempData());
 96			}
 97			return retdir;
 98		}
 99
100		// Description: This function will return the Directory representing the system's temporary files directory. Persistance is not guaranteed.
101		// Returns: The Directory representing the temp location.
102		Directory appDataDir() {
103			return Directory.open(DirectoryGetAppData());
104		}
105
106		// Description: This function will return the Directory representing the system's temporary files directory. Persistance is not guaranteed.
107		// Returns: The Directory representing the temp location.
108		Directory userDataDir() {
109			return Directory.open(DirectoryGetUserData());
110		}
111
112		// Description: This function will return the Directory representing the system's temporary files directory. Persistance is not guaranteed.
113		// Returns: The Directory representing the temp location.
114		Directory binaryDir() {
115			return Directory.open(DirectoryGetBinary());
116		}
117	}
118	
119	class Locale {
120		static:
121		public:
122
123			LocaleId id() {
124				return SystemGetLocaleId();
125			}
126
127			TimeZone timezone() {
128				return new TimeZone();
129			}
130	}
131
132	long time() {
133		return SystemTimeGet();
134	}
135}