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

Commit

Permalink
Fix exception in backup. Change restart behavior again. Timed cleanup…
Browse files Browse the repository at this point in the history
…s can be set to run at hourly intervals.
  • Loading branch information
rexxar-tc committed May 9, 2016
1 parent 6cdeafb commit 5ba205e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 32 deletions.
6 changes: 3 additions & 3 deletions EssentialsPlugin/AssemblyFileVersion.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//117
//140
//
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.
//

using System.Reflection;

[assembly: AssemblyFileVersion("1.13.6.117")]
[assembly: AssemblyVersion("1.13.6.117")]
[assembly: AssemblyFileVersion("1.13.6.140")]
[assembly: AssemblyVersion("1.13.6.140")]
2 changes: 1 addition & 1 deletion EssentialsPlugin/ProcessHandlers/ProcessBackup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void CleanupBackups()
{
Essentials.Log.Info( "Removed old backup: {0}", file );
File.Delete(file);
Directory.Delete(path);
Directory.Delete(path, true);
break;
}
}
Expand Down
29 changes: 17 additions & 12 deletions EssentialsPlugin/ProcessHandlers/ProcessCleanup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

DateTime itemTime = new DateTime( _start.Year, _start.Month, _start.Day, item.Restart.Hour, item.Restart.Minute, 0 );
if ( DateTime.Now - itemTime > _twentySeconds )
{
itemTime = itemTime.AddDays( 1 );
}
if ( !item.Interval )
itemTime = new DateTime( _start.Year, _start.Month, _start.Day, item.Restart.Hour, item.Restart.Minute, 0 );
else
itemTime = new DateTime( _start.Year, _start.Month, _start.Day, _start.Hour, item.Restart.Minute, 0 );

if ( DateTime.Now - itemTime > _twentySeconds )
{
itemTime = itemTime.AddDays( 1 );
}

if ( DateTime.Now - item.LastRan < _oneMinute )
if ( DateTime.Now - item.LastRan < _oneMinute )
return;

if ( itemTime - DateTime.Now < _oneSecond && DateTime.Now - item.LastRan > _oneMinute )
Expand Down Expand Up @@ -101,10 +106,10 @@ private void ProcessTimedItem( SettingsCleanupTimedItem item )
/// <exception cref="OverflowException"></exception>
private void ProcessTriggerItem( SettingsCleanupTriggerItem item )
{
if ( _triggerdItem != null && _triggerdItem != item )
if ( _triggeredItem != null && _triggeredItem != item )
return;

if ( _triggerdItem == null )
if ( _triggeredItem == null )
{
// Increase to 5 minutes
if ( DateTime.Now - item.LastRan > _fiveMinutes )
Expand All @@ -118,9 +123,9 @@ private void ProcessTriggerItem( SettingsCleanupTriggerItem item )

if ( gridsCount >= item.MaxCapacity )
{
Communication.SendPublicInformation( $"[NOTICE]: Cleanup triggered. ({gridsCount} of {item.MaxCapacity}) triggered grids found. Cleanup will run in {item.MinutesAfterCapacity} minutes. Reason: {item.Reason}" );
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}")}" );
item.NotificationItemsRan.Clear( );
_triggerdItem = item;
_triggeredItem = item;
}
}
}
Expand All @@ -139,7 +144,7 @@ private void ProcessTriggerItem( SettingsCleanupTriggerItem item )
group.Close();
}
Communication.SendPublicInformation( $"[NOTICE]: Triggered cleanup has run. {gridCount} grids in {groupCount} groups removed." );
_triggerdItem = null;
_triggeredItem = null;
return;
}

Expand Down
5 changes: 3 additions & 2 deletions EssentialsPlugin/ProcessHandlers/ProcessRestart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ public override void Handle()
private void DoRestart()
{
// Tell SE to shut down
Wrapper.GameAction( ()=>MySandboxGame.Static.Exit( ) );
Thread.Sleep( 15000 );
//Wrapper.GameAction( ()=>MySandboxGame.Static.Exit( ) );
MySandboxGame.Static.Exit( );
//Thread.Sleep( 5000 );
// If we're not a service, restart with a .bat otherwise just exit and let the service be restarted
if (Environment.UserInteractive)
{
Expand Down
23 changes: 21 additions & 2 deletions EssentialsPlugin/Settings/SettingsCleanupTimedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using EssentialsPlugin.UtilityClasses;

public class SettingsCleanupTimedItem
{
public DateTime Restart;
public List<SettingsCleanupNotificationItem> NotificationItemsRan = new List<SettingsCleanupNotificationItem>();
public DateTime LastRan = DateTime.Now.AddDays(-1);
public bool Interval;

private bool enabled;
public bool Enabled
Expand All @@ -20,14 +22,31 @@ public bool Enabled
}

private string restartTime;
//HACK: we can't rename this because loading the saved config will fail and blank the property
//use the DisplayName attribute instead
[Editor(typeof(TimePickerEditor), typeof(UITypeEditor))]
[DisplayName(@"RunTime")]
public string RestartTime
{
get { return restartTime; }
set
{
restartTime = value;
Restart = DateTime.Parse(restartTime);
//Restart = DateTime.Parse(restartTime);
if ( restartTime.StartsWith( "-" ) )
{
if ( restartTime[1] != '1' )
throw new FormatException( "Hours must be between -1 and 23" );

Interval = true;
Restart = DateTime.Parse( restartTime.TrimStart( '-' ) );
}
else
{
Interval = false;
Restart = DateTime.Parse( value );
}

}
}

Expand All @@ -39,7 +58,7 @@ public string ScanCommand
}

private string reason;
public string Reason
public string Reason
{
get { return reason; }
set { reason = value; }
Expand Down
23 changes: 11 additions & 12 deletions EssentialsPlugin/Utility/CubeGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ public static HashSet<GridGroup> ScanGrids( ulong userId, string[] words )
bool hasDisplayName = false;
bool hasDisplayNameExact = false;
bool displayNameGroup = false;
bool hasBlockSubType = false;
bool hasBlockSubTypeLimits = false;
bool includesBlockSubType = false;
bool excludesBlockSubType = false;
bool includesBlockType = false;
bool excludesBlockType = false;
bool debug = false;
Expand Down Expand Up @@ -587,7 +587,7 @@ public static HashSet<GridGroup> ScanGrids( ulong userId, string[] words )
{
string[] parts =
words.FirstOrDefault( x => x.ToLower( ).StartsWith( "includesblocksubtype:" ) ).Split( ':' );
hasBlockSubType = true;
includesBlockSubType = true;
options.Add( "Has Sub Block Type", "true" );

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

if ( parts.Length < 3 )
Expand Down Expand Up @@ -835,17 +835,16 @@ public static HashSet<GridGroup> ScanGrids( ulong userId, string[] words )
if ( requireBlockCountLess && !( group.BlocksCount < blockCountLess ) )
return;
if ( hasBlockSubType && !blockSubTypes.Any( x => DoesGroupHaveBlockSubtype( group, x.Key, x.Value ) ) )
return;
if ( excludesBlockType && blockSubTypes.Any( x => DoesGroupHaveBlockType( group, x.Key, x.Value ) ) )
if ( excludesBlockType && blockTypesExcluded.Any( x => DoesGroupHaveBlockType( group, x.Key, x.Value ) ) )
return;
if ( includesBlockType && !blockTypes.Any( x => DoesGroupHaveBlockType( group, x.Key, x.Value ) ) )
return;
if ( includesBlockSubType && !blockSubTypes.Any( x => DoesGroupHaveBlockSubtype( group, x.Key, x.Value ) ) )
return;
if ( hasBlockSubTypeLimits &&
!blockSubTypes.Any( x => DoesGroupHaveBlockSubtype( group, x.Key, x.Value ) ) )
if ( excludesBlockSubType && blockSubTypes.Any( x => DoesGroupHaveBlockSubtype( group, x.Key, x.Value ) ) )
return;
lock ( groupsFound )
Expand Down Expand Up @@ -1018,9 +1017,9 @@ public static bool AreOwnersOnline( GridGroup group )
public static bool DoesGroupHaveCustomName( GridGroup group, string customName, bool exact = false )
{
if ( !exact )
return group.CubeBlocks.Any( x => x?.FatBlock?.DisplayName != null && x.FatBlock.Name.Contains( customName, StringComparison.CurrentCultureIgnoreCase));
return group.CubeBlocks.Any( x => x?.FatBlock?.DisplayNameText != null && x.FatBlock.DisplayNameText.Contains( customName, StringComparison.CurrentCultureIgnoreCase));
else
return group.CubeBlocks.Any( x => x?.FatBlock?.DisplayName != null && x.FatBlock.Name.Equals( customName,StringComparison.CurrentCultureIgnoreCase ));
return group.CubeBlocks.Any( x => x?.FatBlock?.DisplayNameText != null && x.FatBlock.DisplayNameText.Equals( customName,StringComparison.CurrentCultureIgnoreCase ));
}

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

0 comments on commit 5ba205e

Please sign in to comment.