changeset 1:2007c2cd566a

Add some functions for handeling state
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 10 Sep 2018 14:55:47 +0200
parents a549d0cd3775
children a9795512f33a
files +mpm/clear_state.m +mpm/install_location.m +mpm/load_state.m +mpm/save_state.m .hgignore
diffstat 5 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+mpm/clear_state.m	Mon Sep 10 14:55:47 2018 +0200
@@ -0,0 +1,3 @@
+function clear_state()
+    mpm.save_state(struct());
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+mpm/install_location.m	Mon Sep 10 14:55:47 2018 +0200
@@ -0,0 +1,7 @@
+function p = install_location()
+   nameCurrentFile = mfilename('fullpath');
+   pathParts = split(nameCurrentFile, filesep);
+
+   p = join(pathParts(1:end-2), filesep);
+   p = p{1};
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+mpm/load_state.m	Mon Sep 10 14:55:47 2018 +0200
@@ -0,0 +1,7 @@
+function s = load_state()
+    try
+        s = load(fullfile(mpm.install_location(), 'state'));
+    catch
+        s = struct();
+    end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+mpm/save_state.m	Mon Sep 10 14:55:47 2018 +0200
@@ -0,0 +1,3 @@
+function save_state(s)
+    save(fullfile(mpm.install_location(), 'state'), '-struct', 's');
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Mon Sep 10 14:55:47 2018 +0200
@@ -0,0 +1,2 @@
+syntax:glob
+state.mat