Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymacdonald committed Jan 4, 2023
2 parents 09c7d0a + 46374b9 commit dd60452
Show file tree
Hide file tree
Showing 108 changed files with 109,676 additions and 2,770 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,6 @@ HeliosDisplayManagement.Setup/HeliosDisplayManagement.Setup/*
/MigrationBackup
/Notes
/DisplayMagician/Resources/settings.png
/UpgradeReport.sarif
/upgrade-assistant.clef
/AnalysisReport.sarif
197 changes: 197 additions & 0 deletions DMv2.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions DisplayMagician/AppLibraries/App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Text.RegularExpressions;
using DisplayMagician.GameLibraries;
using Newtonsoft.Json;

namespace DisplayMagician.AppLibraries
{
public class App
{

private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private bool isUWP = false;


#region Properties
public virtual string Id { get; set; }

public virtual SupportedAppLibraryType AppLibraryType { get; }

public virtual AppLibrary AppLibrary { get; }

public virtual bool IsRunning { get; set; }

public virtual bool IsUpdating { get; set; }

public virtual string Name { get; set; }

public virtual string ExePath { get; set; }

public virtual bool ExecutableArgumentsRequired { get; set; }

public virtual string Arguments { get; set; }

public virtual string IconPath { get; set; }

public virtual string Directory { get; set; }

public virtual string ProcessName { get; set; }

public virtual List<Process> Processes { get; set; }

public ShortcutBitmap AppBitmap { get; set; }

public List<ShortcutBitmap> AvailableAppBitmaps { get; set; }

#endregion


#region Methods

public virtual bool CopyTo(App steamApp)
{
return true;
}

public virtual bool Start(out List<Process> processesStarted, string gameArguments = "", ProcessPriority priority = ProcessPriority.Normal, int timeout = 20, bool runExeAsAdmin = false)
{
processesStarted = new List<Process>();
return true;
}

public virtual bool Stop()
{
return true;
}

#endregion
}
}
286 changes: 286 additions & 0 deletions DisplayMagician/AppLibraries/AppLibrary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Threading.Tasks;
using DisplayMagician;
using Newtonsoft.Json;

namespace DisplayMagician.AppLibraries
{
public enum SupportedAppLibraryType
{
Unknown = 0,
Local = 1,
}

public class AppLibrary
{

private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();

#region Class Properties

public static List<App> AllInstalledAppsInAllLibraries { get; set; }
public static bool AppsLoaded { get; set; } = false;

public static bool AppImagesLoaded { get; set; } = false;

public virtual List<App> AllInstalledApps { get; set; }

public virtual int InstalledAppCount { get; set; }

public virtual string AppLibraryName { get; set; }

public virtual SupportedAppLibraryType AppLibraryType { get; set; }

public virtual string AppLibraryExe { get; set; }

public virtual string AppLibraryPath { get; set; }

public virtual bool IsAppLibraryInstalled { get; set; }

public virtual bool IsRunning { get; set; }

public virtual bool IsUpdating { get; set; }

public virtual List<string> AppLibraryProcesses { get; set; }
#endregion

#region Class Methods
public virtual bool AddApp(App app)
{
return false;
}

public virtual bool RemoveApp(App app)
{
return false;
}

public virtual bool RemoveAppById(string appId)
{
return false;
}

public virtual bool RemoveApp(string appNameOrId)
{
return false;
}

public virtual bool ContainsApp(App app)
{
return false;
}

public virtual bool ContainsAppById(string appId)
{
return false;
}

public virtual bool ContainsApp(string appNameOrId)
{
return false;
}


public virtual App GetApp(string appNameOrId)
{
return null;
}

public virtual App GetAppById(string appId)
{
return null;
}

public virtual bool LoadInstalledApps()
{
return false;
}

public virtual List<Process> StartApp(App App, string AppArguments = "", ProcessPriority processPriority = ProcessPriority.Normal)
{
return null;
}

public virtual bool StopApp(App App)
{
return false;
}
public virtual bool AppIsRunning(App App)
{
return false;
}

public static App GetAnyAppById(string appId)
{
App appToUse = null;
foreach (App app in AppLibrary.AllInstalledAppsInAllLibraries)
{
if (app.Id.Equals(appId))
{
appToUse = app;
break;
}
}

if (appToUse is App)
{
logger.Info($"AppLibrary/GetAppById: Found App {appToUse.Name} from ID {appId}");
return appToUse;
}
else
{
logger.Info($"AppLibrary/GetAppById: Didn't find App {appToUse.Name} from ID {appId}");
return appToUse;
}
}

public static bool LoadAppsInBackground()
{

logger.Trace($"AppLibrary/LoadAppsInBackground: Attempting to load Apps from detected App libraries.");

// Clear the App libraries in case this is a refresh
LocalLibrary localLibrary = LocalLibrary.GetLibrary();
localLibrary.AllInstalledApps.Clear();

// Now lets prepare loading all the Local Apps we have installed
Action loadLocalAppsAction = new Action(() =>
{
// Check wht local apps are installed
//LocalLibrary localLibrary = LocalLibrary.GetLibrary();
if (localLibrary.IsAppLibraryInstalled)
{
// Load local library Apps
logger.Info($"AppLibrary/LoadAppsInBackground: Loading Locally Installed Apps");
if (!localLibrary.LoadInstalledApps())
{
logger.Info($"AppLibrary/LoadAppsInBackground: Cannot load Locally Installed Apps!");
}
logger.Info($"AppLibrary/LoadAppsInBackground: Loaded all Locally Installed Apps (found {localLibrary.InstalledAppCount})");
}
else
{
logger.Info($"AppLibrary/LoadAppsInBackground: Locally installed app library not installed.");
Console.WriteLine("Locally installed app not installed.");
}
});


// Store all the actions in a array so we can wait on them later
List<Action> loadAppsActions = new List<Action>();
loadAppsActions.Add(loadLocalAppsAction);

try
{
logger.Debug($"AppLibrary/LoadAppsInBackground: Running App loading actions.");
// Go through and start all the actions, making sure we only have one threat per action to avoid thread issues
int threads = loadAppsActions.Count;
ParallelOptions options = new ParallelOptions { MaxDegreeOfParallelism = threads };
Parallel.Invoke(options, loadAppsActions.ToArray());
// Once we get here , we know that all the parallel actions have returned
logger.Debug($"AppLibrary/LoadAppsInBackground: All App loading tasks finished");
}
catch (Exception ae)
{
logger.Error(ae, $"AppLibrary/LoadAppsInBackground: One or more exception during execution of loadAppsActions");
}

// Produce a single array of Apps we can reference later
AppLibrary.AllInstalledAppsInAllLibraries = new List<App>();
AppLibrary.AllInstalledAppsInAllLibraries.AddRange(localLibrary.AllInstalledApps);

AppsLoaded = true;

return true;
}

public static void RefreshAppBitmaps()
{
// Create App Bitmaps from the Apps so the rest of the program is faster later
// Get the bitmap out of the IconPath
// IconPath can be an ICO, or an EXE
foreach (var App in AppLibrary.AllInstalledAppsInAllLibraries)
{
List<ShortcutBitmap> bmList = new List<ShortcutBitmap>();

try
{

/*ArrayList filesToSearchForIcon = new ArrayList();
filesToSearchForIcon.Add(App.ExePath);
if (App.IconPath != App.ExePath)
filesToSearchForIcon.Add(App.IconPath);
bm = ImageUtils.GetMeABitmapFromFile(filesToSearchForIcon);*/

// We only want the icon location that the AppLibrary told us to use
// Note: This may be an icon file, or an exe file.
// This function tries to get a 256x256 Vista sized bitmap from the file
logger.Trace($"Program/LoadAppsInBackground: Attempting to get App bitmaps from {App.Name}.");
bmList.AddRange(ImageUtils.GetMeAllBitmapsFromFile(App.IconPath));
/*if (App.ExePath != App.IconPath && !App.ExePath.Contains("explorer.exe"))
{
bmList.AddRange(ImageUtils.GetMeAllBitmapsFromFile(App.ExePath));
}*/
logger.Trace($"Program/LoadAppsInBackground: Got App bitmaps from {App.Name}.");

}
catch (Exception ex)
{
logger.Error(ex, $"Program/LoadAppsInBackground: Exception building App bitmaps for {App.Name} during load");
}

// Only copy across the new bitmaps we've got (leaving the ones already there
foreach (var bm in bmList)
{
if (!App.AvailableAppBitmaps.Contains(bm))
{
App.AvailableAppBitmaps.Add(bm);
}
}

if (App.AvailableAppBitmaps.Count == 0)
{
ShortcutBitmap bm = new ShortcutBitmap();
if (App.AppLibraryType.Equals(SupportedAppLibraryType.Local))
{
bm = ImageUtils.CreateShortcutBitmap(Properties.Resources.exe, "Exe Icon", App.ExePath, 0);
}
else
{
bm = ImageUtils.CreateShortcutBitmap(Properties.Resources.DisplayMagician.ToBitmap(), "DisplayMagician Icon", App.ExePath, 0);
}
// Add the shortcutbitmap to the list
App.AvailableAppBitmaps.Add(bm);
App.AppBitmap = bm;
}
else
{
App.AppBitmap = ImageUtils.GetMeLargestAvailableBitmap(bmList);
}

}
AppImagesLoaded = true;
}



#endregion

}

[global::System.Serializable]
public class AppLibraryException : Exception
{
public AppLibraryException() { }
public AppLibraryException(string message) : base(message) { }
public AppLibraryException(string message, Exception inner) : base(message, inner) { }
protected AppLibraryException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}

}

0 comments on commit dd60452

Please sign in to comment.