Website may be up and down over next few months. I'm currently doing a complete overhaul of everything. Going back to simple individual .htm pages, new overall site theme, sanitizing and cleaning up html of all pages and blog posts, attempting to implement a new tooling and publishing system etc etc.

Some .net/mono frameworks do not support the 3 argument GetDirectories method. The code below provides a simple replacement.

/// <summary>
/// Builds an array of folders & sub folders.
/// </summary>
/// <param name="path">The path to search.</param>
/// <param name="pattern">The search string to match against the names of files in path. The parameter cannot end in two periods 
/// ("..") or contain two periods ("..") followed by System.IO.Path.DirectorySeparatorChar or System.IO.Path.AltDirectorySeparatorChar,
/// nor can it contain any of the characters in System.IO.Path.InvalidPathChars.
///</param>
/// <param name="searchOptions">One of the System.IO.SearchOption values that specifies whether the search operation should include 
/// all subdirectories or only the current directory.
///</param>
/// <returns>A String array of directories that match the search pattern.</returns>
public static string[] GetDirectories(string path, string pattern, SearchOption searchOptions)
{
    // check if searching for all directories
    if (searchOptions == SearchOption.AllDirectories)
    {
        // add start paths to list
        var list = Directory.GetDirectories(path, pattern);
        var index = 0;
        var count = list.Length;

        // process list and add folders to end of list
        while (index < count)
        {
            var directories = Directory.GetDirectories(list[index++], pattern);
            if (directories.Length > 0)
            {
                // check if we need more space to store the directories
                if (count + directories.Length > list.Length - 1)
                {
                    Array.Resize(ref list, list.Length + directories.Length + 1000);
                }

                // add directories to end of the list
                foreach (var directory in directories)
                {
                    list[count++] = directory;
                }
            }

            // trim unused index from end of the array
            if (list.Length > count)
            {
                Array.Resize(ref list, count);
            }
        }

        return list;
    }

    // just return initial list of folder with no sub folders
    return Directory.GetDirectories(path, pattern);
}

/// <summary>
/// Provides a game object that automatically self terminates.
/// </summary>
[ExecuteInEditMode]
public class SelfTerminatingObject : MonoBehaviour
{
    /// <summary>
    /// Holds a reference to a callback that will be called just before termination.
    /// </summary>
    public Action Callback;

    /// <summary>
    /// Holds the time delay in seconds before object self terminates.
    /// </summary>
    public float Delay;

    /// <summary>
    /// Holds a time value used to determine whether it's time to self terminate.
    /// </summary>
    private DateTime lastTime;

    /// <summary>
    /// Called by Unity to update the object.
    /// </summary>
    public void Update()
    {
        this.PerformCheck();
    }

    /// <summary>
    /// Called by Unity to draw the object's GUI.
    /// </summary>
    public void OnGui()
    {
        this.PerformCheck();
    }

    /// <summary>
    /// Determines whether it's time to terminate.
    /// </summary>
    private void PerformCheck()
    {
        // check if specified time span has elapsed
        if (DateTime.Now > this.lastTime + TimeSpan.FromSeconds(this.Delay))
        {
            // run callback is specified
            if (this.Callback != null)
            {
                this.Callback();
            }

            // destroy object
#if UNITY_EDITOR
        DestroyImmediate(this.gameObject, true);
#else
            Destroy(this.gameObject);
#endif
        }
    }

    /// <summary>
    /// Creates a self terminating game object.
    /// </summary>
    /// <param name="callback">The method to be called before the object terminates.</param>
    /// <returns>Returns a reference to the game object that will self terminate.</returns>
    public static GameObject CreateUpdateCallback(Action callback)
    {
        return CreateUpdateCallback(callback, 0);
    }

    /// <summary>
    /// Creates a self terminating game object.
    /// </summary>
    /// <param name="callback">The method to be called before the object terminates.</param>
    /// <param name="delay">Specifies a delay value in seconds before the object will self terminate.</param>
    /// <returns>Returns a reference to the game object that will self terminate.</returns>
    public static GameObject CreateUpdateCallback(Action callback, float delay)
    {
        var obj = new GameObject();
        var com = obj.AddComponent<SelfTerminatingObject>();
        com.lastTime = DateTime.Now;
        com.Delay = delay;
        com.Callback = callback;

        return obj;
    }
}

File Backup Solutions

Published 3/1/2013 by createdbyx in News
Tags:

I have been procrastinating whether or not to write my own open source Google Drive / DropBox clone in C# for some time now. I’ve been looking for a cloud based backup solution but am to cheap to pay and have only used the free storage that DropBox, Google Drive & SkyDrive offer. Google Drive & DropBox work awesome and seamlessly but I have had various “issues” with SkyDrive.

The reason I wanted to write my own clone of these cloud based storage solutions is because I am already paying for “Unlimited” storage with my web hosting account that this site and all my other web sites are hosted from. So for me to pay extra for storage on SkyDrive, DropBox etc doesn't make much sense.

I used to use SyncBack for a while but stopped using it. I started looking around for free alternatives and came across Duplicati. Duplicati is almost what I had planed on making myself. it’s open source, written in C# and can back up files to a multitude of storage destinations like SkyDrive, Google Drive, FTP etc. It’s multi platform (Mac, Win, Linux) & it supports encryption, compression & incremental backups! It’s pretty much everything I could have hoped for and a little bit more.

Although I have not used it for very long I think I may have found a backup solution I can live with.


Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume