Skip to content

Commit

Permalink
First Version. Hardcoded Model Name only tested on the Legion Go
Browse files Browse the repository at this point in the history
  • Loading branch information
NightHammer1000 committed Nov 23, 2023
1 parent 4d72f02 commit 0ea0895
Show file tree
Hide file tree
Showing 12 changed files with 412 additions and 0 deletions.
12 changes: 12 additions & 0 deletions App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<Style x:Key="BaseTextBlockStyle" TargetType="TextBlock" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Localization/en_US.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
5 changes: 5 additions & 0 deletions Localization/en_US.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">

</ResourceDictionary>
109 changes: 109 additions & 0 deletions MicroSDInstallStatusUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using Playnite.SDK;
using Playnite.SDK.Events;
using Playnite.SDK.Models;
using Playnite.SDK.Plugins;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace MicroSDInstallStatusUpdater
{
public class MicroSDInstallStatusUpdater : GenericPlugin
{
private static readonly ILogger logger = LogManager.GetLogger();

private MicroSDInstallStatusUpdaterSettingsViewModel settings { get; set; }

public override Guid Id { get; } = Guid.Parse("216a1883-0794-4381-b5e3-8ccf42ad1463");

public MicroSDInstallStatusUpdater(IPlayniteAPI api) : base(api)
{
settings = new MicroSDInstallStatusUpdaterSettingsViewModel(this);
Properties = new GenericPluginProperties
{
HasSettings = false
};
}

public override void OnApplicationStarted(OnApplicationStartedEventArgs args)
{
var insertWatcher = new ManagementEventWatcher(new WqlEventQuery(
"__InstanceCreationEvent", new TimeSpan(0, 0, 1),
"TargetInstance isa 'Win32_DiskDrive' AND TargetInstance.Model LIKE '%SDXC Card%'"));
insertWatcher.EventArrived += SDCardInserted;
logger.Info("[SDCardInstallStatusUpdater] SDCard Insert Watcher Registered!");

var removeWatcher = new ManagementEventWatcher(new WqlEventQuery(
"__InstanceDeletionEvent", new TimeSpan(0, 0, 1),
"TargetInstance isa 'Win32_DiskDrive' AND TargetInstance.Model LIKE '%SDXC Card%'"));
removeWatcher.EventArrived += SDCardRemoved;
logger.Info("[SDCardInstallStatusUpdater] SDCard Remove Watcher Registered!");
logger.Info("[SDCardInstallStatusUpdater] SDCard Watc");

insertWatcher.Start();
removeWatcher.Start();
}

private void SDCardRemoved(object sender, EventArrivedEventArgs e)
{
logger.Info("[SDCardInstallStatusUpdater] SDCard Removed! Updating Database!");
foreach (var game in PlayniteApi.Database.Games)
{
var InstallDir = game.InstallDirectory;

if (!Directory.Exists(InstallDir) || InstallDir == null)
{
logger.Info("[SDCardInstallStatusUpdater] Game '" + game.Name + "' is not found anymore. Updateing Status to Uninstalled");
game.IsInstalled = false;
PlayniteApi.Database.Games.Update(game);
}
if (Directory.Exists(InstallDir))
{
logger.Info("[SDCardInstallStatusUpdater] Game '" + game.Name + "' is now found!. Updateing Status to Installed");
game.IsInstalled = true;
PlayniteApi.Database.Games.Update(game);
}
}
}

private void SDCardInserted(object sender, EventArrivedEventArgs e)
{
logger.Info("[SDCardInstallStatusUpdater] SDCard Inserted! Sleeping a bit to let Windows handle and mount shit :3 Updating Database!");
Thread.Sleep(5000);
logger.Info("[SDCardInstallStatusUpdater] Sleep Done! Updating Database!");
foreach (var game in PlayniteApi.Database.Games)
{
var InstallDir = game.InstallDirectory;

if(!Directory.Exists(InstallDir) || InstallDir == null)
{
logger.Info("[SDCardInstallStatusUpdater] Game '" + game.Name + "' is not found anymore. Updateing Status to Uninstalled");
game.IsInstalled = false;
PlayniteApi.Database.Games.Update(game);
}
if (Directory.Exists(InstallDir))
{
logger.Info("[SDCardInstallStatusUpdater] Game '" + game.Name + "' is now found!. Updateing Status to Installed");
game.IsInstalled = true;
PlayniteApi.Database.Games.Update(game);
}
}
}

public override ISettings GetSettings(bool firstRunSettings)
{
return settings;
}

public override UserControl GetSettingsView(bool firstRunSettings)
{
return new MicroSDInstallStatusUpdaterSettingsView();
}
}
}
86 changes: 86 additions & 0 deletions MicroSDInstallStatusUpdater.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MicroSDInstallStatusUpdater</RootNamespace>
<AssemblyName>MicroSDInstallStatusUpdater</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Playnite.SDK, Version=6.10.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\PlayniteSDK.6.10.0\lib\net462\Playnite.SDK.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Management" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="MicroSDInstallStatusUpdater.cs" />
<Compile Include="MicroSDInstallStatusUpdaterSettings.cs" />
<Compile Include="MicroSDInstallStatusUpdaterSettingsView.xaml.cs">
<DependentUpon>MicroSDInstallStatusUpdaterSettingsView.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="extension.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<None Include="Localization\*.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Page Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="MicroSDInstallStatusUpdaterSettingsView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<None Include="icon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
25 changes: 25 additions & 0 deletions MicroSDInstallStatusUpdater.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34212.112
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MicroSDInstallStatusUpdater", "MicroSDInstallStatusUpdater.csproj", "{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {620DAE38-0360-4A4F-A05E-7FE07CD0E592}
EndGlobalSection
EndGlobal
89 changes: 89 additions & 0 deletions MicroSDInstallStatusUpdaterSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using Playnite.SDK;
using Playnite.SDK.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MicroSDInstallStatusUpdater
{
public class MicroSDInstallStatusUpdaterSettings : ObservableObject
{
private string option1 = string.Empty;
private bool option2 = false;
private bool optionThatWontBeSaved = false;

public string Option1 { get => option1; set => SetValue(ref option1, value); }
public bool Option2 { get => option2; set => SetValue(ref option2, value); }
// Playnite serializes settings object to a JSON object and saves it as text file.
// If you want to exclude some property from being saved then use `JsonDontSerialize` ignore attribute.
[DontSerialize]
public bool OptionThatWontBeSaved { get => optionThatWontBeSaved; set => SetValue(ref optionThatWontBeSaved, value); }
}

public class MicroSDInstallStatusUpdaterSettingsViewModel : ObservableObject, ISettings
{
private readonly MicroSDInstallStatusUpdater plugin;
private MicroSDInstallStatusUpdaterSettings editingClone { get; set; }

private MicroSDInstallStatusUpdaterSettings settings;
public MicroSDInstallStatusUpdaterSettings Settings
{
get => settings;
set
{
settings = value;
OnPropertyChanged();
}
}

public MicroSDInstallStatusUpdaterSettingsViewModel(MicroSDInstallStatusUpdater plugin)
{
// Injecting your plugin instance is required for Save/Load method because Playnite saves data to a location based on what plugin requested the operation.
this.plugin = plugin;

// Load saved settings.
var savedSettings = plugin.LoadPluginSettings<MicroSDInstallStatusUpdaterSettings>();

// LoadPluginSettings returns null if no saved data is available.
if (savedSettings != null)
{
Settings = savedSettings;
}
else
{
Settings = new MicroSDInstallStatusUpdaterSettings();
}
}

public void BeginEdit()
{
// Code executed when settings view is opened and user starts editing values.
editingClone = Serialization.GetClone(Settings);
}

public void CancelEdit()
{
// Code executed when user decides to cancel any changes made since BeginEdit was called.
// This method should revert any changes made to Option1 and Option2.
Settings = editingClone;
}

public void EndEdit()
{
// Code executed when user decides to confirm changes made since BeginEdit was called.
// This method should save settings made to Option1 and Option2.
plugin.SavePluginSettings(Settings);
}

public bool VerifySettings(out List<string> errors)
{
// Code execute when user decides to confirm changes made since BeginEdit was called.
// Executed before EndEdit is called and EndEdit is not called if false is returned.
// List of errors is presented to user if verification fails.
errors = new List<string>();
return true;
}
}
}
14 changes: 14 additions & 0 deletions MicroSDInstallStatusUpdaterSettingsView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<UserControl x:Class="MicroSDInstallStatusUpdater.MicroSDInstallStatusUpdaterSettingsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="600">
<StackPanel>
<TextBlock Text="Description for Option1:"/>
<TextBox Text="{Binding Settings.Option1}"/>
<TextBlock Text="Description for Option2:"/>
<CheckBox IsChecked="{Binding Settings.Option2}"/>
</StackPanel>
</UserControl>
25 changes: 25 additions & 0 deletions MicroSDInstallStatusUpdaterSettingsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MicroSDInstallStatusUpdater
{
public partial class MicroSDInstallStatusUpdaterSettingsView : UserControl
{
public MicroSDInstallStatusUpdaterSettingsView()
{
InitializeComponent();
}
}
}
Loading

0 comments on commit 0ea0895

Please sign in to comment.