2
using TeeJee.FileSystem;
3
using TeeJee.JsonHelper;
4
using TeeJee.ProcessHelper;
5
using TeeJee.GtkHelper;
9
public class CryptTabEntry : GLib.Object{
10
public bool is_comment = false;
11
public bool is_empty_line = false;
14
public string mapped_name = "";
15
public string device_string = "";
16
public string keyfile = "none";
17
public string options = "luks,nofail";
18
public string line = "";
20
public string device_uuid {
22
if (device_string.down().has_prefix("uuid=")){
23
return device_string.replace("\"","").replace("'","").split("=")[1];
30
device_string = "UUID=%s".printf(value);
34
public static Gee.ArrayList<CryptTabEntry> read_file(string file_path){
35
var list = new Gee.ArrayList<CryptTabEntry>();
37
if (!file_exists(file_path)){ return list; }
39
string text = file_read(file_path);
40
string[] lines = text.split("\n");
41
foreach(string line in lines){
42
var entry = new CryptTabEntry();
45
entry.is_comment = line.strip().has_prefix("#");
46
entry.is_empty_line = (line.strip().length == 0);
48
if (entry.is_comment){
51
else if (entry.is_empty_line){
57
string[] parts = line.replace("\t"," ").split(" ");
59
foreach(string part in parts){
60
if (part.strip().length == 0) { continue; }
63
entry.mapped_name = part.strip();
66
entry.device_string = part.strip();
69
entry.keyfile = part.strip();
72
entry.options = part.strip();
82
public static string write_file(
83
Gee.ArrayList<CryptTabEntry> entries, string file_path,
84
bool keep_comments_and_empty_lines = true){
87
foreach(var entry in entries){
88
if (entry.is_comment || entry.is_empty_line){
89
if (keep_comments_and_empty_lines){
90
text += "%s\n".printf(entry.line);
94
text += "%s\t%s\t%s\t%s\n".printf(
95
entry.mapped_name, entry.device_string,
96
entry.keyfile, entry.options);
100
if (file_exists(file_path)){
101
file_delete(file_path);
104
file_write(file_path, text);
109
public void append_option(string option){
111
if (!options.contains(option)){
112
options += ",%s".printf(option);
115
if(options.has_prefix(",")){
116
options = options[1:options.length];
119
options = options.strip();
122
public void remove_option(string option){
124
options = options.replace(option,"").strip();
126
if(options.has_prefix(",")){
127
options = options[1:options.length];
130
if (options.has_suffix(",")){
131
options = options[0:options.length - 1];
134
options = options.strip();
137
public static CryptTabEntry? find_entry_by_uuid(
138
Gee.ArrayList<CryptTabEntry> entries, string uuid){
140
foreach(var entry in entries){
141
if (entry.device_uuid == uuid){