2
0
Эх сурвалжийг харах

tools: delete logs when expired

Daniele Bartolini 5 жил өмнө
parent
commit
795ecba7a3

+ 1 - 0
docs/changelog.rst

@@ -16,6 +16,7 @@ Changelog
 
 **Tools**
 
+* Added logs expiration option to Preferences dialog
 * Added the ability to select from a number of templates (samples) when creating new projects
 * Fixed an issue that caused the Level Editor to ask multiple times whether save the level in some circumnstances
 * Level Editor now restores the Console's history from previous sessions

+ 41 - 0
tools/level_editor/level_editor.vala

@@ -459,6 +459,47 @@ public class LevelEditorApplication : Gtk.Application
 		_main_stack.add_named(_main_vbox, "main_vbox");
 
 		load_settings();
+
+		// Delete expired logs
+		if (_preferences_dialog._log_delete_after_days.value != 0)
+		{
+			try
+			{
+				FileEnumerator enumerator = _logs_dir.enumerate_children("standard::*"
+					, FileQueryInfoFlags.NOFOLLOW_SYMLINKS
+					);
+				GLib.FileInfo info = null;
+				while ((info = enumerator.next_file()) != null)
+				{
+					if (info.get_file_type() != GLib.FileType.REGULAR)
+						continue; // Skip anything but regular files
+
+					// Parse DateTime from log filename
+					int year = 1970;
+					int month = 1;
+					int day = 1;
+					if (info.get_name().scanf("%d-%d-%d.log", &year, &month, &day) != 3)
+						continue; // Skip malformed filenames
+
+					GLib.DateTime time_log = new GLib.DateTime.utc(year, month, day, 0, 0, 0.0);
+					if (time_log == null)
+						continue; // Skip invalid dates
+
+					GLib.DateTime time_now = new GLib.DateTime.now_utc();
+					if (time_now.difference(time_log) <= GLib.TimeSpan.DAY*_preferences_dialog._log_delete_after_days.value)
+						continue; // Skip if date is within range
+
+					// Delete
+					GLib.File log_file = _logs_dir.resolve_relative_path(info.get_name());
+					log_file.delete();
+				}
+			}
+			catch (GLib.Error e)
+			{
+				loge(e.message);
+			}
+		}
+
 		_user.load(_user_file.get_path());
 		_console_view._entry_history.load(_console_history_file.get_path());
 

+ 15 - 9
tools/level_editor/preferences_dialog.vala

@@ -12,32 +12,35 @@ namespace Crown
 public class PreferencesDialog : Gtk.Dialog
 {
 	// Data
-	LevelEditorApplication _application;
+	public LevelEditorApplication _application;
 
 	// Widgets
 	[GtkChild]
-	ColorButtonVector3 _grid_color_button;
+	public ColorButtonVector3 _grid_color_button;
 
 	[GtkChild]
-	ColorButtonVector3 _grid_disabled_color_button;
+	public ColorButtonVector3 _grid_disabled_color_button;
 
 	[GtkChild]
-	ColorButtonVector3 _axis_x_color_button;
+	public ColorButtonVector3 _axis_x_color_button;
 
 	[GtkChild]
-	ColorButtonVector3 _axis_y_color_button;
+	public ColorButtonVector3 _axis_y_color_button;
 
 	[GtkChild]
-	ColorButtonVector3 _axis_z_color_button;
+	public ColorButtonVector3 _axis_z_color_button;
 
 	[GtkChild]
-	ColorButtonVector3 _axis_selected_color_button;
+	public ColorButtonVector3 _axis_selected_color_button;
 
 	[GtkChild]
-	Gtk.SpinButton _gizmo_size_spin_button;
+	public Gtk.SpinButton _gizmo_size_spin_button;
 
 	[GtkChild]
-	Gtk.SpinButton _level_autosave_spin_button;
+	public Gtk.SpinButton _level_autosave_spin_button;
+
+	[GtkChild]
+	public Gtk.SpinButton _log_delete_after_days;
 
 	public PreferencesDialog(LevelEditorApplication app)
 	{
@@ -80,6 +83,7 @@ public class PreferencesDialog : Gtk.Dialog
 		_axis_selected_color_button.value = Vector3.from_array(preferences.has_key("axis_selected") ? (Gee.ArrayList<GLib.Value?>)preferences["axis_selected"] : _axis_selected_color_button.value.to_array());
 		_gizmo_size_spin_button.value     = preferences.has_key("gizmo_size") ? (double)preferences["gizmo_size"] : _gizmo_size_spin_button.value;
 		_level_autosave_spin_button.value = preferences.has_key("autosave_timer") ? (double)preferences["autosave_timer"] : _level_autosave_spin_button.value;
+		_log_delete_after_days.value      = preferences.has_key("log_expiration") ? (double)preferences["log_expiration"] : _log_delete_after_days.value;
 	}
 
 	public void save(Hashtable preferences)
@@ -92,6 +96,7 @@ public class PreferencesDialog : Gtk.Dialog
 		preferences["axis_selected"]  = _axis_selected_color_button.value.to_array();
 		preferences["gizmo_size"]     = _gizmo_size_spin_button.value;
 		preferences["autosave_timer"] = _level_autosave_spin_button.value;
+		preferences["log_expiration"] = _log_delete_after_days.value;
 	}
 
 	public void apply()
@@ -99,6 +104,7 @@ public class PreferencesDialog : Gtk.Dialog
 		GLib.Signal.emit_by_name(_grid_color_button, "color-set");
 		GLib.Signal.emit_by_name(_gizmo_size_spin_button, "value-changed");
 		GLib.Signal.emit_by_name(_level_autosave_spin_button, "value-changed");
+		GLib.Signal.emit_by_name(_log_delete_after_days, "value-changed");
 	}
 }
 

+ 184 - 88
tools/level_editor/resources/ui/preferences_dialog.ui

@@ -1,35 +1,41 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.36.0 -->
+<!-- Generated with glade 3.38.2 -->
 <interface>
   <requires lib="gtk+" version="3.16"/>
   <object class="GtkAdjustment" id="adjustment1">
     <property name="lower">10</property>
     <property name="upper">200</property>
     <property name="value">85</property>
-    <property name="step_increment">1</property>
-    <property name="page_increment">10</property>
+    <property name="step-increment">1</property>
+    <property name="page-increment">10</property>
   </object>
   <object class="GtkAdjustment" id="adjustment2">
     <property name="lower">1</property>
     <property name="upper">60</property>
     <property name="value">5</property>
-    <property name="step_increment">1</property>
-    <property name="page_increment">10</property>
+    <property name="step-increment">1</property>
+    <property name="page-increment">10</property>
+  </object>
+  <object class="GtkAdjustment" id="adjustment3">
+    <property name="upper">90</property>
+    <property name="value">10</property>
+    <property name="step-increment">1</property>
+    <property name="page-increment">10</property>
   </object>
   <template class="CrownPreferencesDialog" parent="GtkDialog">
-    <property name="can_focus">False</property>
+    <property name="can-focus">False</property>
     <property name="resizable">False</property>
-    <property name="window_position">center</property>
-    <property name="type_hint">dialog</property>
-    <property name="skip_taskbar_hint">True</property>
+    <property name="window-position">center</property>
+    <property name="type-hint">dialog</property>
+    <property name="skip-taskbar-hint">True</property>
     <child internal-child="vbox">
       <object class="GtkBox">
-        <property name="can_focus">False</property>
+        <property name="can-focus">False</property>
         <property name="orientation">vertical</property>
         <child internal-child="action_area">
           <object class="GtkButtonBox">
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
+            <property name="can-focus">False</property>
+            <property name="layout-style">end</property>
             <child>
               <placeholder/>
             </child>
@@ -46,20 +52,21 @@
         <child>
           <object class="GtkNotebook">
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="show_border">False</property>
+            <property name="can-focus">True</property>
+            <property name="show-border">False</property>
             <child>
+              <!-- n-columns=3 n-rows=10 -->
               <object class="GtkGrid">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="margin_bottom">18</property>
-                <property name="border_width">12</property>
-                <property name="row_spacing">6</property>
-                <property name="column_spacing">12</property>
+                <property name="can-focus">False</property>
+                <property name="margin-bottom">18</property>
+                <property name="border-width">12</property>
+                <property name="row-spacing">6</property>
+                <property name="column-spacing">12</property>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can-focus">False</property>
                     <property name="label" translatable="yes">Grid</property>
                     <property name="xalign">0</property>
                     <attributes>
@@ -67,8 +74,8 @@
                     </attributes>
                   </object>
                   <packing>
-                    <property name="left_attach">0</property>
-                    <property name="top_attach">0</property>
+                    <property name="left-attach">0</property>
+                    <property name="top-attach">0</property>
                   </packing>
                 </child>
                 <child>
@@ -83,20 +90,20 @@
                     <signal name="color-set" handler="on_color_set" swapped="no"/>
                   </object>
                   <packing>
-                    <property name="left_attach">2</property>
-                    <property name="top_attach">1</property>
+                    <property name="left-attach">2</property>
+                    <property name="top-attach">1</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can-focus">False</property>
                     <property name="label" translatable="yes">Grid</property>
                     <property name="xalign">1</property>
                   </object>
                   <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">1</property>
+                    <property name="left-attach">1</property>
+                    <property name="top-attach">1</property>
                   </packing>
                 </child>
                 <child>
@@ -111,26 +118,26 @@
                     <signal name="color-set" handler="on_color_set" swapped="no"/>
                   </object>
                   <packing>
-                    <property name="left_attach">2</property>
-                    <property name="top_attach">2</property>
+                    <property name="left-attach">2</property>
+                    <property name="top-attach">2</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can-focus">False</property>
                     <property name="label" translatable="yes">Grid (Disabled)</property>
                     <property name="xalign">1</property>
                   </object>
                   <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">2</property>
+                    <property name="left-attach">1</property>
+                    <property name="top-attach">2</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can-focus">False</property>
                     <property name="label" translatable="yes">Axes</property>
                     <property name="xalign">0</property>
                     <attributes>
@@ -138,8 +145,8 @@
                     </attributes>
                   </object>
                   <packing>
-                    <property name="left_attach">0</property>
-                    <property name="top_attach">3</property>
+                    <property name="left-attach">0</property>
+                    <property name="top-attach">3</property>
                   </packing>
                 </child>
                 <child>
@@ -154,44 +161,44 @@
                     <signal name="color-set" handler="on_color_set" swapped="no"/>
                   </object>
                   <packing>
-                    <property name="left_attach">2</property>
-                    <property name="top_attach">4</property>
+                    <property name="left-attach">2</property>
+                    <property name="top-attach">4</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can-focus">False</property>
                     <property name="label" translatable="yes">X Axis</property>
                     <property name="xalign">1</property>
                   </object>
                   <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">4</property>
+                    <property name="left-attach">1</property>
+                    <property name="top-attach">4</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can-focus">False</property>
                     <property name="label" translatable="yes">Y Axis</property>
                     <property name="xalign">1</property>
                   </object>
                   <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">5</property>
+                    <property name="left-attach">1</property>
+                    <property name="top-attach">5</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can-focus">False</property>
                     <property name="label" translatable="yes">Z Axis</property>
                     <property name="xalign">1</property>
                   </object>
                   <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">6</property>
+                    <property name="left-attach">1</property>
+                    <property name="top-attach">6</property>
                   </packing>
                 </child>
                 <child>
@@ -206,8 +213,8 @@
                     <signal name="color-set" handler="on_color_set" swapped="no"/>
                   </object>
                   <packing>
-                    <property name="left_attach">2</property>
-                    <property name="top_attach">5</property>
+                    <property name="left-attach">2</property>
+                    <property name="top-attach">5</property>
                   </packing>
                 </child>
                 <child>
@@ -222,20 +229,20 @@
                     <signal name="color-set" handler="on_color_set" swapped="no"/>
                   </object>
                   <packing>
-                    <property name="left_attach">2</property>
-                    <property name="top_attach">6</property>
+                    <property name="left-attach">2</property>
+                    <property name="top-attach">6</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can-focus">False</property>
                     <property name="label" translatable="yes">Selected</property>
                     <property name="xalign">1</property>
                   </object>
                   <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">7</property>
+                    <property name="left-attach">1</property>
+                    <property name="top-attach">7</property>
                   </packing>
                 </child>
                 <child>
@@ -249,14 +256,14 @@
                     <signal name="color-set" handler="on_color_set" swapped="no"/>
                   </object>
                   <packing>
-                    <property name="left_attach">2</property>
-                    <property name="top_attach">7</property>
+                    <property name="left-attach">2</property>
+                    <property name="top-attach">7</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can-focus">False</property>
                     <property name="label" translatable="yes">Gizmo</property>
                     <property name="xalign">0</property>
                     <attributes>
@@ -264,34 +271,34 @@
                     </attributes>
                   </object>
                   <packing>
-                    <property name="left_attach">0</property>
-                    <property name="top_attach">8</property>
+                    <property name="left-attach">0</property>
+                    <property name="top-attach">8</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can-focus">False</property>
                     <property name="label" translatable="yes">Size (px)</property>
                     <property name="xalign">1</property>
                   </object>
                   <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">9</property>
+                    <property name="left-attach">1</property>
+                    <property name="top-attach">9</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkSpinButton" id="_gizmo_size_spin_button">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
+                    <property name="can-focus">True</property>
                     <property name="hexpand">True</property>
                     <property name="adjustment">adjustment1</property>
                     <property name="value">85</property>
                     <signal name="value-changed" handler="on_gizmo_size_value_changed" swapped="no"/>
                   </object>
                   <packing>
-                    <property name="left_attach">2</property>
-                    <property name="top_attach">9</property>
+                    <property name="left-attach">2</property>
+                    <property name="top-attach">9</property>
                   </packing>
                 </child>
                 <child>
@@ -338,26 +345,27 @@
             <child type="tab">
               <object class="GtkLabel">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Viewport</property>
+                <property name="can-focus">False</property>
+                <property name="label" translatable="yes">Document</property>
               </object>
               <packing>
-                <property name="position">1</property>
-                <property name="tab_fill">False</property>
+                <property name="position">2</property>
+                <property name="tab-fill">False</property>
               </packing>
             </child>
             <child>
+              <!-- n-columns=3 n-rows=3 -->
               <object class="GtkGrid">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="margin_bottom">18</property>
-                <property name="border_width">12</property>
-                <property name="row_spacing">6</property>
-                <property name="column_spacing">12</property>
+                <property name="can-focus">False</property>
+                <property name="margin-bottom">18</property>
+                <property name="border-width">12</property>
+                <property name="row-spacing">6</property>
+                <property name="column-spacing">12</property>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can-focus">False</property>
                     <property name="label" translatable="yes">Level</property>
                     <property name="xalign">0</property>
                     <attributes>
@@ -365,33 +373,115 @@
                     </attributes>
                   </object>
                   <packing>
-                    <property name="left_attach">0</property>
-                    <property name="top_attach">0</property>
+                    <property name="left-attach">0</property>
+                    <property name="top-attach">0</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can-focus">False</property>
                     <property name="label" translatable="yes">Autosave (mins)</property>
                     <property name="xalign">1</property>
                   </object>
                   <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">1</property>
+                    <property name="left-attach">1</property>
+                    <property name="top-attach">1</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkSpinButton" id="_level_autosave_spin_button">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
+                    <property name="can-focus">True</property>
                     <property name="hexpand">True</property>
                     <property name="adjustment">adjustment2</property>
                     <signal name="value-changed" handler="on_level_autosave_value_changed" swapped="no"/>
                   </object>
                   <packing>
-                    <property name="left_attach">2</property>
-                    <property name="top_attach">1</property>
+                    <property name="left-attach">2</property>
+                    <property name="top-attach">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can-focus">False</property>
+                <property name="label" translatable="yes">Viewport</property>
+              </object>
+              <packing>
+                <property name="position">1</property>
+                <property name="tab-fill">False</property>
+              </packing>
+            </child>
+            <child>
+              <!-- n-columns=3 n-rows=3 -->
+              <object class="GtkGrid">
+                <property name="visible">True</property>
+                <property name="can-focus">False</property>
+                <property name="margin-bottom">18</property>
+                <property name="border-width">12</property>
+                <property name="row-spacing">6</property>
+                <property name="column-spacing">12</property>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can-focus">False</property>
+                    <property name="label" translatable="yes">Memory and Limits</property>
+                    <property name="xalign">0</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="left-attach">0</property>
+                    <property name="top-attach">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can-focus">False</property>
+                    <property name="label" translatable="yes">Delete logs after (days):</property>
+                    <property name="xalign">1</property>
+                  </object>
+                  <packing>
+                    <property name="left-attach">1</property>
+                    <property name="top-attach">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkSpinButton" id="_log_delete_after_days">
+                    <property name="visible">True</property>
+                    <property name="can-focus">True</property>
+                    <property name="adjustment">adjustment3</property>
+                    <property name="value">10</property>
+                  </object>
+                  <packing>
+                    <property name="left-attach">2</property>
+                    <property name="top-attach">1</property>
                   </packing>
                 </child>
                 <child>
@@ -403,6 +493,15 @@
                 <child>
                   <placeholder/>
                 </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
               </object>
               <packing>
                 <property name="position">2</property>
@@ -411,12 +510,12 @@
             <child type="tab">
               <object class="GtkLabel">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Document</property>
+                <property name="can-focus">False</property>
+                <property name="label" translatable="yes">System</property>
               </object>
               <packing>
                 <property name="position">2</property>
-                <property name="tab_fill">False</property>
+                <property name="tab-fill">False</property>
               </packing>
             </child>
           </object>
@@ -428,8 +527,5 @@
         </child>
       </object>
     </child>
-    <child type="titlebar">
-      <placeholder/>
-    </child>
   </template>
 </interface>