using System; using System.Collections.Generic; using System.Text; using OnTopReplica.Platforms; using System.Windows.Forms; namespace OnTopReplica { abstract class PlatformSupport { /// /// Creates a concrete PlatformSupport instance based on the OS the app is running on. /// public static PlatformSupport Create() { var os = Environment.OSVersion; var platform = CreateFromOperatingSystem(os); Log.Write("{0} detected, using support class {1}", os.VersionString, platform.GetType().FullName); return platform; } private static PlatformSupport CreateFromOperatingSystem(OperatingSystem os) { if (os.Platform != PlatformID.Win32NT) return new Other(); if (os.Version.Major == 6) { if (os.Version.Minor >= 2) return new WindowsEight(); else if (os.Version.Minor == 1) return new WindowsSeven(); else return new WindowsVista(); } else if (os.Version.Major > 6) { //Ensures forward compatibility return new WindowsSeven(); } else { //Generic NT return new WindowsXp(); } } /// /// Checks whether OnTopReplica is compatible with the platform. /// /// Returns false if OnTopReplica cannot run and should terminate right away. public abstract bool CheckCompatibility(); /// /// Initializes a form before it is fully constructed and before the window handle has been created. /// public virtual void PreHandleFormInit() { } /// /// Initializes a form after its handle has been created. /// /// Form to initialize. public virtual void PostHandleFormInit(MainForm form) { } /// /// Called before closing a form. Called once during a form's lifetime. /// public virtual void CloseForm(MainForm form) { } /// /// Hides the main form in a way that it can be restored later by the user. /// /// Form to hide. public virtual void HideForm(MainForm form) { } /// /// Gets whether the form is currently hidden or not. /// public virtual bool IsHidden(MainForm form) { return false; } /// /// Restores the main form to its default state after is has been hidden. /// Can be called whether the form is hidden or not. /// /// Form to restore. public virtual void RestoreForm(MainForm form) { } /// /// Called when the form changes its state, without calling into or . /// Enables inheritors to update the form's state on each state change. /// public virtual void OnFormStateChange(MainForm form) { } } }