Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 5ba205e

Browse files
committed
Fix exception in backup. Change restart behavior again. Timed cleanups can be set to run at hourly intervals.
1 parent 6cdeafb commit 5ba205e

File tree

6 files changed

+56
-32
lines changed

6 files changed

+56
-32
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//117
1+
//140
22
//
33
// This code was generated by a tool. Any changes made manually will be lost
44
// the next time this code is regenerated.
55
//
66

77
using System.Reflection;
88

9-
[assembly: AssemblyFileVersion("1.13.6.117")]
10-
[assembly: AssemblyVersion("1.13.6.117")]
9+
[assembly: AssemblyFileVersion("1.13.6.140")]
10+
[assembly: AssemblyVersion("1.13.6.140")]

EssentialsPlugin/ProcessHandlers/ProcessBackup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private void CleanupBackups()
6161
{
6262
Essentials.Log.Info( "Removed old backup: {0}", file );
6363
File.Delete(file);
64-
Directory.Delete(path);
64+
Directory.Delete(path, true);
6565
break;
6666
}
6767
}

EssentialsPlugin/ProcessHandlers/ProcessCleanup.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class ProcessCleanup : ProcessHandlerBase
1111
{
12-
private SettingsCleanupTriggerItem _triggerdItem;
12+
private SettingsCleanupTriggerItem _triggeredItem;
1313
private DateTime _start = DateTime.Now;
1414
private readonly TimeSpan _oneSecond = new TimeSpan( 0, 0, 1 );
1515
private readonly TimeSpan _twentySeconds = new TimeSpan( 0, 0, 20 );
@@ -50,14 +50,19 @@ public override void Handle( )
5050
private void ProcessTimedItem( SettingsCleanupTimedItem item )
5151
{
5252
_start = DateTime.Now; // this needs to be updated for each run so multi-day runtimes are handled properly
53+
DateTime itemTime;
5354

54-
DateTime itemTime = new DateTime( _start.Year, _start.Month, _start.Day, item.Restart.Hour, item.Restart.Minute, 0 );
55-
if ( DateTime.Now - itemTime > _twentySeconds )
56-
{
57-
itemTime = itemTime.AddDays( 1 );
58-
}
55+
if ( !item.Interval )
56+
itemTime = new DateTime( _start.Year, _start.Month, _start.Day, item.Restart.Hour, item.Restart.Minute, 0 );
57+
else
58+
itemTime = new DateTime( _start.Year, _start.Month, _start.Day, _start.Hour, item.Restart.Minute, 0 );
59+
60+
if ( DateTime.Now - itemTime > _twentySeconds )
61+
{
62+
itemTime = itemTime.AddDays( 1 );
63+
}
5964

60-
if ( DateTime.Now - item.LastRan < _oneMinute )
65+
if ( DateTime.Now - item.LastRan < _oneMinute )
6166
return;
6267

6368
if ( itemTime - DateTime.Now < _oneSecond && DateTime.Now - item.LastRan > _oneMinute )
@@ -101,10 +106,10 @@ private void ProcessTimedItem( SettingsCleanupTimedItem item )
101106
/// <exception cref="OverflowException"></exception>
102107
private void ProcessTriggerItem( SettingsCleanupTriggerItem item )
103108
{
104-
if ( _triggerdItem != null && _triggerdItem != item )
109+
if ( _triggeredItem != null && _triggeredItem != item )
105110
return;
106111

107-
if ( _triggerdItem == null )
112+
if ( _triggeredItem == null )
108113
{
109114
// Increase to 5 minutes
110115
if ( DateTime.Now - item.LastRan > _fiveMinutes )
@@ -118,9 +123,9 @@ private void ProcessTriggerItem( SettingsCleanupTriggerItem item )
118123

119124
if ( gridsCount >= item.MaxCapacity )
120125
{
121-
Communication.SendPublicInformation( $"[NOTICE]: Cleanup triggered. ({gridsCount} of {item.MaxCapacity}) triggered grids found. Cleanup will run in {item.MinutesAfterCapacity} minutes. Reason: {item.Reason}" );
126+
Communication.SendPublicInformation( $"[NOTICE]: Cleanup triggered. ({gridsCount} of {item.MaxCapacity}) triggered grids found. Cleanup will run in {item.MinutesAfterCapacity} minutes.{(item.Reason == string.Empty ? "" : $" Reason: {item.Reason}")}" );
122127
item.NotificationItemsRan.Clear( );
123-
_triggerdItem = item;
128+
_triggeredItem = item;
124129
}
125130
}
126131
}
@@ -139,7 +144,7 @@ private void ProcessTriggerItem( SettingsCleanupTriggerItem item )
139144
group.Close();
140145
}
141146
Communication.SendPublicInformation( $"[NOTICE]: Triggered cleanup has run. {gridCount} grids in {groupCount} groups removed." );
142-
_triggerdItem = null;
147+
_triggeredItem = null;
143148
return;
144149
}
145150

EssentialsPlugin/ProcessHandlers/ProcessRestart.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ public override void Handle()
9595
private void DoRestart()
9696
{
9797
// Tell SE to shut down
98-
Wrapper.GameAction( ()=>MySandboxGame.Static.Exit( ) );
99-
Thread.Sleep( 15000 );
98+
//Wrapper.GameAction( ()=>MySandboxGame.Static.Exit( ) );
99+
MySandboxGame.Static.Exit( );
100+
//Thread.Sleep( 5000 );
100101
// If we're not a service, restart with a .bat otherwise just exit and let the service be restarted
101102
if (Environment.UserInteractive)
102103
{

EssentialsPlugin/Settings/SettingsCleanupTimedItem.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
using System.Collections.Generic;
55
using System.ComponentModel;
66
using System.Drawing.Design;
7+
using System.Windows.Forms;
78
using EssentialsPlugin.UtilityClasses;
89

910
public class SettingsCleanupTimedItem
1011
{
1112
public DateTime Restart;
1213
public List<SettingsCleanupNotificationItem> NotificationItemsRan = new List<SettingsCleanupNotificationItem>();
1314
public DateTime LastRan = DateTime.Now.AddDays(-1);
15+
public bool Interval;
1416

1517
private bool enabled;
1618
public bool Enabled
@@ -20,14 +22,31 @@ public bool Enabled
2022
}
2123

2224
private string restartTime;
25+
//HACK: we can't rename this because loading the saved config will fail and blank the property
26+
//use the DisplayName attribute instead
2327
[Editor(typeof(TimePickerEditor), typeof(UITypeEditor))]
28+
[DisplayName(@"RunTime")]
2429
public string RestartTime
2530
{
2631
get { return restartTime; }
2732
set
2833
{
2934
restartTime = value;
30-
Restart = DateTime.Parse(restartTime);
35+
//Restart = DateTime.Parse(restartTime);
36+
if ( restartTime.StartsWith( "-" ) )
37+
{
38+
if ( restartTime[1] != '1' )
39+
throw new FormatException( "Hours must be between -1 and 23" );
40+
41+
Interval = true;
42+
Restart = DateTime.Parse( restartTime.TrimStart( '-' ) );
43+
}
44+
else
45+
{
46+
Interval = false;
47+
Restart = DateTime.Parse( value );
48+
}
49+
3150
}
3251
}
3352

@@ -39,7 +58,7 @@ public string ScanCommand
3958
}
4059

4160
private string reason;
42-
public string Reason
61+
public string Reason
4362
{
4463
get { return reason; }
4564
set { reason = value; }

EssentialsPlugin/Utility/CubeGrid.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ public static HashSet<GridGroup> ScanGrids( ulong userId, string[] words )
433433
bool hasDisplayName = false;
434434
bool hasDisplayNameExact = false;
435435
bool displayNameGroup = false;
436-
bool hasBlockSubType = false;
437-
bool hasBlockSubTypeLimits = false;
436+
bool includesBlockSubType = false;
437+
bool excludesBlockSubType = false;
438438
bool includesBlockType = false;
439439
bool excludesBlockType = false;
440440
bool debug = false;
@@ -587,7 +587,7 @@ public static HashSet<GridGroup> ScanGrids( ulong userId, string[] words )
587587
{
588588
string[] parts =
589589
words.FirstOrDefault( x => x.ToLower( ).StartsWith( "includesblocksubtype:" ) ).Split( ':' );
590-
hasBlockSubType = true;
590+
includesBlockSubType = true;
591591
options.Add( "Has Sub Block Type", "true" );
592592

593593
if ( parts.Length < 3 )
@@ -608,7 +608,7 @@ public static HashSet<GridGroup> ScanGrids( ulong userId, string[] words )
608608
{
609609
string[] parts =
610610
words.FirstOrDefault( x => x.ToLower( ).StartsWith( "excludesblocksubtype:" ) ).Split( ':' );
611-
hasBlockSubTypeLimits = true;
611+
excludesBlockSubType = true;
612612
options.Add( "Exclude Has Sub Block Type", "true" );
613613

614614
if ( parts.Length < 3 )
@@ -835,17 +835,16 @@ public static HashSet<GridGroup> ScanGrids( ulong userId, string[] words )
835835
if ( requireBlockCountLess && !( group.BlocksCount < blockCountLess ) )
836836
return;
837837

838-
if ( hasBlockSubType && !blockSubTypes.Any( x => DoesGroupHaveBlockSubtype( group, x.Key, x.Value ) ) )
839-
return;
840-
841-
if ( excludesBlockType && blockSubTypes.Any( x => DoesGroupHaveBlockType( group, x.Key, x.Value ) ) )
838+
if ( excludesBlockType && blockTypesExcluded.Any( x => DoesGroupHaveBlockType( group, x.Key, x.Value ) ) )
842839
return;
843840

844841
if ( includesBlockType && !blockTypes.Any( x => DoesGroupHaveBlockType( group, x.Key, x.Value ) ) )
845842
return;
843+
844+
if ( includesBlockSubType && !blockSubTypes.Any( x => DoesGroupHaveBlockSubtype( group, x.Key, x.Value ) ) )
845+
return;
846846

847-
if ( hasBlockSubTypeLimits &&
848-
!blockSubTypes.Any( x => DoesGroupHaveBlockSubtype( group, x.Key, x.Value ) ) )
847+
if ( excludesBlockSubType && blockSubTypes.Any( x => DoesGroupHaveBlockSubtype( group, x.Key, x.Value ) ) )
849848
return;
850849

851850
lock ( groupsFound )
@@ -1018,9 +1017,9 @@ public static bool AreOwnersOnline( GridGroup group )
10181017
public static bool DoesGroupHaveCustomName( GridGroup group, string customName, bool exact = false )
10191018
{
10201019
if ( !exact )
1021-
return group.CubeBlocks.Any( x => x?.FatBlock?.DisplayName != null && x.FatBlock.Name.Contains( customName, StringComparison.CurrentCultureIgnoreCase));
1020+
return group.CubeBlocks.Any( x => x?.FatBlock?.DisplayNameText != null && x.FatBlock.DisplayNameText.Contains( customName, StringComparison.CurrentCultureIgnoreCase));
10221021
else
1023-
return group.CubeBlocks.Any( x => x?.FatBlock?.DisplayName != null && x.FatBlock.Name.Equals( customName,StringComparison.CurrentCultureIgnoreCase ));
1022+
return group.CubeBlocks.Any( x => x?.FatBlock?.DisplayNameText != null && x.FatBlock.DisplayNameText.Equals( customName,StringComparison.CurrentCultureIgnoreCase ));
10241023
}
10251024

10261025
public static bool DoesGroupHaveDisplayName( GridGroup group, string displayName, bool exact = false, bool grouped = false )

0 commit comments

Comments
 (0)