Skip to content

Commit

Permalink
GNOME 47 update
Browse files Browse the repository at this point in the history
Also remove half of the shredding data for a more sensible shred time.
  • Loading branch information
ADBeveridge committed Dec 20, 2024
1 parent f5e32c0 commit 8c363db
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 75 deletions.
2 changes: 1 addition & 1 deletion com.github.ADBeveridge.Raider.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"app-id" : "com.github.ADBeveridge.Raider",
"runtime" : "org.gnome.Platform",
"runtime-version" : "46",
"runtime-version" : "47",
"sdk" : "org.gnome.Sdk",
"command" : "raider",
"finish-args" : [
Expand Down
10 changes: 10 additions & 0 deletions data/com.github.ADBeveridge.Raider.metainfo.xml.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
<color type="primary" scheme_preference="dark">#5c0012</color>
</branding>
<releases>
<release version="3.0.2" date="2024-07-24">
<description translate="no">
<p>Update for GNOME 47</p>
<ul>
<li>Includes new file picker</li>
<li>Halve shredding time by using more sensible iteration count</li>
<li>Update Occitan, Slovenian and Italian translations</li>
</ul>
</description>
</release>
<release version="3.0.1" date="2024-07-24">
<description translate="no">
<p>Improve icons and branding</p>
Expand Down
123 changes: 61 additions & 62 deletions src/corrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
#include <glib/gi18n.h>
#include "corrupt.h"

// The size of this array is how many times the file will be overwritten.
const char* steps[] = {"\x77\x77\x77", "\x76\x76\x76",
"\x33\x33\x33", "\x35\x35\x35",
"\x55\x55\x55", "\xAA\xAA\xAA",
"\x44\x44\x44", "\x55\x55\x55",
"\x66\x66\x66", "\x77\x77\x77"};
"\x33\x33\x33", "\x35\x35\x35", "\x55\x55\x55"};

struct _RaiderCorrupt
{
Expand All @@ -47,6 +45,7 @@ uint8_t corrupt_unlink_file(const char *filename);
uint8_t corrupt_unlink_folder(const char *filename);
off_t corrupt_check_file(const char *filename);
static uint8_t corrupt_step(GTask* task, const char* filename, const off_t filesize, const char *pattern, int loop_num);
void shredding_thread (GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable);


static void raider_corrupt_init(RaiderCorrupt *self)
Expand All @@ -67,6 +66,17 @@ RaiderCorrupt *raider_corrupt_new(GFile* file, RaiderFileRow* row)
return corrupt;
}

GCancellable* raider_corrupt_start_shredding(RaiderCorrupt* self, GAsyncReadyCallback func)
{
self->cancel = g_cancellable_new();
self->task = g_task_new(self, self->cancel, func, NULL);
g_task_set_task_data (self->task, self->row, NULL);
g_task_run_in_thread(self->task, shredding_thread);
g_object_unref(self->task);

return self->cancel;
}

void shredding_thread (GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable)
{
RaiderCorrupt* corrupt = RAIDER_CORRUPT(source_object);
Expand All @@ -84,39 +94,6 @@ void shredding_thread (GTask *task, gpointer source_object, gpointer task_data,
}
}

GCancellable* raider_corrupt_start_shredding(RaiderCorrupt* self, GAsyncReadyCallback func)
{
self->cancel = g_cancellable_new();
self->task = g_task_new(self, self->cancel, func, NULL);
g_task_set_task_data (self->task, self->row, NULL);
g_task_run_in_thread(self->task, shredding_thread);
g_object_unref(self->task);

return self->cancel;
}

/* Your standard recursive file listing algorithm. */
static void list_files(const char *directory, GPtrArray* files) {
const gchar *file_name;

GDir *dir = g_dir_open(directory, 0, NULL);
if (dir != NULL) {
while ((file_name = g_dir_read_name(dir)) != NULL) {
gchar *file_path = g_build_filename(directory, file_name, NULL);
// If it is another directory, recurse.
if (g_file_test(file_path, G_FILE_TEST_IS_DIR)) {
// Make sure it is not the current or parent directories.
if (strcmp(file_name, ".") != 0 && strcmp(file_name, "..") != 0) {
list_files(file_path, files);
}
} else {
g_ptr_array_add(files, file_path);
}
}
g_dir_close(dir);
}
}

int corrupt_folder(RaiderCorrupt* corrupt)
{
char* folder = g_file_get_path(corrupt->file);
Expand Down Expand Up @@ -169,13 +146,13 @@ uint8_t corrupt_file(RaiderCorrupt* corrupt)
raider_file_row_set_progress_num(corrupt->row, corrupt->progress);
g_main_context_invoke (NULL, raider_file_row_set_progress, corrupt->row);

// Shred the file by overwriting it many times.
off_t filesize = corrupt_check_file(filename);
if (filesize == -1)
{
return -1;
}

// Shred the file by overwriting it many times.
uint8_t i;
for (i = 0; i < steps_num; i++)
{
Expand Down Expand Up @@ -221,30 +198,6 @@ static uint8_t corrupt_step(GTask* task, const char* filename, const off_t files
return ret;
}

off_t corrupt_check_file(const char *filename)
{
struct stat st;

// Run some checks on the file.
if(lstat(filename, &st) != 0)
{
fprintf(stderr, "corrupt: current file not found\n");
return -1;
}
if (S_ISLNK(st.st_mode) == 1)
{
/* Quietly deal with symbolic links. */
corrupt_unlink_file(filename);
return -1;
}
if (S_ISREG(st.st_mode) == 0)
{
fprintf(stderr, "corrupt: current file is not a regular file\n");
return -1;
}
return st.st_size;
}

uint8_t corrupt_unlink_file(const char *filename)
{
uint8_t ret = 0;
Expand Down Expand Up @@ -289,3 +242,49 @@ uint8_t corrupt_unlink_folder(const char *directory)

return 0;
}

off_t corrupt_check_file(const char *filename)
{
struct stat st;

// Run some checks on the file.
if(lstat(filename, &st) != 0)
{
fprintf(stderr, "corrupt: current file not found\n");
return -1;
}
if (S_ISLNK(st.st_mode) == 1)
{
/* Quietly deal with symbolic links. */
corrupt_unlink_file(filename);
return -1;
}
if (S_ISREG(st.st_mode) == 0)
{
fprintf(stderr, "corrupt: current file is not a regular file\n");
return -1;
}
return st.st_size;
}

// Standard directory scanner.
static void list_files(const char *directory, GPtrArray* files) {
const gchar *file_name;

GDir *dir = g_dir_open(directory, 0, NULL);
if (dir != NULL) {
while ((file_name = g_dir_read_name(dir)) != NULL) {
gchar *file_path = g_build_filename(directory, file_name, NULL);
// If it is another directory, recurse.
if (g_file_test(file_path, G_FILE_TEST_IS_DIR)) {
// Make sure it is not the current or parent directories.
if (strcmp(file_name, ".") != 0 && strcmp(file_name, "..") != 0) {
list_files(file_path, files);
}
} else {
g_ptr_array_add(files, file_path);
}
}
g_dir_close(dir);
}
}
2 changes: 1 addition & 1 deletion src/raider-file-row.blp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Gtk 4.0;
using Adw 1;

template RaiderFileRow : Adw.ActionRow {
template $RaiderFileRow : Adw.ActionRow {
selectable: false;
activatable: true;

Expand Down
2 changes: 1 addition & 1 deletion src/raider-progress-info-popover.blp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Gtk 4.0;
using Adw 1;

template RaiderProgressInfoPopover : Gtk.Popover {
template $RaiderProgressInfoPopover : Gtk.Popover {
Gtk.Box popover_box {
Gtk.ProgressBar progress_bar {
show-text: true;
Expand Down
4 changes: 2 additions & 2 deletions src/raider-progress-info-popover.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void raider_progress_info_popover_set_progress(RaiderProgressInfoPopover *popove
if (percentage == 0)
{
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(popover->progress_bar), _("Starting…"));
gtk_progress_bar_pulse(GTK_PROGRESS_BAR(popover->progress_bar));
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(popover->progress_bar), 1);
}
else if (percentage < 100)
{
Expand All @@ -72,6 +72,6 @@ void raider_progress_info_popover_set_progress(RaiderProgressInfoPopover *popove
/* This is used when the spinner is shown instead of the progress icon. */
void raider_progress_info_popover_pulse(RaiderProgressInfoPopover *popover)
{
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(popover->progress_bar), _("Estimating..."));
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(popover->progress_bar), _("Estimating"));
gtk_progress_bar_pulse(GTK_PROGRESS_BAR(popover->progress_bar));
}
2 changes: 1 addition & 1 deletion src/raider-window.blp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Gtk 4.0;
using Adw 1;

template RaiderWindow : Adw.ApplicationWindow {
template $RaiderWindow : Adw.ApplicationWindow {
default-width: 800;
default-height: 600;
width-request: 360;
Expand Down
13 changes: 6 additions & 7 deletions src/raider-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,15 @@ gboolean raider_window_exit(RaiderWindow *win, gpointer data)
{
if (win->status)
{
GtkWidget *dialog = adw_message_dialog_new(GTK_WINDOW(win), _("Stop Shredding?"), NULL);
adw_message_dialog_set_body(ADW_MESSAGE_DIALOG(dialog), _("Are you sure that you want to exit?"));
AdwDialog *dialog = adw_alert_dialog_new(_("Stop Shredding?"), _("Are you sure that you want to exit?"));
g_signal_connect(dialog, "response", G_CALLBACK(raider_window_exit_response), win);

adw_message_dialog_add_responses(ADW_MESSAGE_DIALOG(dialog), "cancel", _("_Cancel"), "exit", _("_Exit"), NULL);
adw_message_dialog_set_response_appearance(ADW_MESSAGE_DIALOG(dialog), "exit", ADW_RESPONSE_DESTRUCTIVE);
adw_message_dialog_set_default_response(ADW_MESSAGE_DIALOG(dialog), "cancel");
adw_message_dialog_set_close_response(ADW_MESSAGE_DIALOG(dialog), "cancel");
adw_alert_dialog_add_responses(ADW_ALERT_DIALOG(dialog), "cancel", _("_Cancel"), "exit", _("_Exit"), NULL);
adw_alert_dialog_set_response_appearance(ADW_ALERT_DIALOG(dialog), "exit", ADW_RESPONSE_DESTRUCTIVE);
adw_alert_dialog_set_default_response(ADW_ALERT_DIALOG(dialog), "cancel");
adw_alert_dialog_set_close_response(ADW_ALERT_DIALOG(dialog), "cancel");

gtk_window_present(GTK_WINDOW(dialog));
adw_dialog_present (dialog, GTK_WIDGET(win));
}

// Based on the value of this, the window will exit or will not.
Expand Down

0 comments on commit 8c363db

Please sign in to comment.