diff --git a/Makefile b/Makefile index d14d3d7..87b9cd8 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ nostalgia: Main.vala Window.vala HeaderBar.vala Nostalgia.vala - valac --pkg libnotify --pkg gtk+-3.0 --pkg gio-2.0 Main.vala Window.vala HeaderBar.vala Nostalgia.vala -o nostalgia + valac --pkg libnotify --pkg gtk+-3.0 --pkg gio-2.0 --pkg glib-2.0 Main.vala Window.vala HeaderBar.vala Nostalgia.vala -o nostalgia install: nostalgia nostalgia-launcher.desktop cp ./nostalgia /usr/bin/ diff --git a/Window.vala b/Window.vala index 00b2b69..9798c19 100644 --- a/Window.vala +++ b/Window.vala @@ -181,6 +181,58 @@ so please be patient and let us get your system back and running"), true, false, var finbutcr = new Gtk.Button.with_label("✔ Make snapshot"); finbutcr.override_background_color(Gtk.StateFlags.NORMAL, green_color); cr12.pack_end(finbutcr, false, false, 10); + + + //CONFIG FILE + + //var ExcludeFolders = ExcludeList.get_buffer().get_text(ExcludeList.get_buffer().get_start_iter(), ExcludeList.get_buffer().get_end_iter(), false); + + //var ExcludeFolders = ExcludeList.buffer.text; + + //print(ExcludeFolders); + + var configData = ""; + + var configFolderLoc = GLib.Environment.get_home_dir().concat("/.config/nostalgia"); + + print(configFolderLoc); + + File configFolder = File.new_for_path(configFolderLoc); + + if(!configFolder.query_exists()) configFolder.make_directory(); + + var configFileLoc = configFolderLoc.concat("/exclude_list.txt"); + + File configFile = File.new_for_path(configFileLoc); + + if(configFile.query_exists()){ + //config file exists + print("\nREADING CONFIG FILE\n"); + FileInputStream @is = configFile.read(); + DataInputStream dis = new DataInputStream(@is); + string line; + print("\nFILE OPENED\n"); + while((line = dis.read_line()) != null){ + print("\nREAD LINE\n"); + configData = configData.concat(line, "\n"); + print("\nDONE\n"); + } + if(configData == ""){ + configFile.replace_contents("/dev\n/proc\n/sys\n/tmp\n/run\n/mnt\n/media\n/cdrom\n/lost+found\n\n".data, null, false, FileCreateFlags.NONE, null); + configData = "/dev\n/proc\n/sys\n/tmp\n/run\n/mnt\n/media\n/cdrom\n/lost+found\n\n"; + } + ExcludeList.buffer.text = configData; + + }else{ + //no config file yet + configFile.create(FileCreateFlags.PRIVATE); + configFile.replace_contents("/dev\n/proc\n/sys\n/tmp\n/run\n/mnt\n/media\n/cdrom\n/lost+found\n\n".data, null, false, FileCreateFlags.NONE, null); + configData = "/dev\n/proc\n/sys\n/tmp\n/run\n/mnt\n/media\n/cdrom\n/lost+found\n\n"; + ExcludeList.buffer.text = configData; + } + + + finbutcr.clicked.connect (() => { if(!ssnap){ print(crloc1.get_filename()); @@ -202,14 +254,17 @@ so please be patient and let us get your system back and running"), true, false, }else{ ssnap=true; createstack.set_visible_child(progresscr); - string isfile; - Process.spawn_command_line_sync("file " + crloc1.get_filename() + "/nostalgia.file", out isfile); + //string isfile; + //Process.spawn_command_line_sync("file " + crloc1.get_filename() + "/nostalgia.file", out isfile); + + //DONE (dumb af that i didnt do this in the first place lazy ahh): Make this use fs syscalls instead of spawning a process - //TODO: Make this use fs syscalls instead of spawning a process + //string isft = crloc1.get_filename() + "/nostalgia.file: empty "; - string isft = crloc1.get_filename() + "/nostalgia.file: empty "; - print(isfile); - print(isft); + File nostalgiaFile = File.new_for_path(crloc1.get_filename().concat("/nostalgia.file")); + + + bool isNostalgiaFile = nostalgiaFile.query_exists(); var lbl = new Gtk.TextView(); lbl.set_wrap_mode (Gtk.WrapMode.WORD); @@ -231,8 +286,7 @@ so please be patient and let us get your system back and running"), true, false, progresscr.pack_end(ProgLabel); - //The length will never be the same if the file is not found - if(isfile.char_count() != isft.char_count()){ + if(!isNostalgiaFile){ print("\n root backup \n"); string testx; //Process.spawn_command_line_sync("bash command", out testx); @@ -247,14 +301,14 @@ so please be patient and let us get your system back and running"), true, false, int dum; bool lop=true; - string[] backup_command_template = {"/usr/bin/pkexec", "/usr/bin/rsync", "-ahv", "/home/ioachim/Music", "/home/ioachim/Music2", "--no-i-r", "--info=progress2", "--fsync", null}; - // --exclude-from="file.txt" EXCLUDES CONTENTS OF FILE EACH ON A LINE - //TODO: Create config file ~/.config/nostalgia/exclude_list.txt using GLib.Environment.get_home_dir() and FileUtils and read exclude list from that (piped directly from tetxbox) + ExcludeList.buffer.text = ExcludeList.buffer.text.concat("\n"); - var ExcludeFolders = ExcludeList.get_buffer().get_text(ExcludeList.get_buffer().get_start_iter(), ExcludeList.get_buffer().get_end_iter(), false); - //FIXME: DOESNT WORK ANYMORE?????? - + configFile.replace_contents(ExcludeList.buffer.text.data, null, false, FileCreateFlags.NONE, null); + + string[] backup_command_template = {"/usr/bin/pkexec", "/usr/bin/rsync", "-ahv", "/home/ioachim/Music", "/home/ioachim/Music2", "--no-i-r", "--info=progress2", "--fsync", "--exclude-from=".concat(configFileLoc), null}; + // --exclude-from="file.txt" EXCLUDES CONTENTS OF FILE EACH ON A LINE + //TODO: Replace command with proper one var ChildProcessBackup = new Subprocess.newv(backup_command_template, SubprocessFlags.STDOUT_PIPE); diff --git a/listbox b/listbox deleted file mode 100755 index bff3888..0000000 Binary files a/listbox and /dev/null differ diff --git a/nostalgia b/nostalgia index e090d8e..6fd09dc 100755 Binary files a/nostalgia and b/nostalgia differ