Skip to content

Commit

Permalink
Initial re-implementation from Machina-only loader to generic loader
Browse files Browse the repository at this point in the history
  • Loading branch information
valarnin committed Aug 13, 2019
1 parent 477663b commit b570c27
Show file tree
Hide file tree
Showing 7 changed files with 496 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
25 changes: 25 additions & 0 deletions ACTAssemblyLoader.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 15
VisualStudioVersion = 15.0.28307.757
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ACTAssemblyLoader", "ACTAssemblyLoader\ACTAssemblyLoader.csproj", "{8DEF8763-7845-4364-B9D9-CE2C9DA5CE6C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8DEF8763-7845-4364-B9D9-CE2C9DA5CE6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8DEF8763-7845-4364-B9D9-CE2C9DA5CE6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DEF8763-7845-4364-B9D9-CE2C9DA5CE6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DEF8763-7845-4364-B9D9-CE2C9DA5CE6C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6EEE0C5A-D7D8-4F24-8A80-CF22A62A051E}
EndGlobalSection
EndGlobal
103 changes: 103 additions & 0 deletions ACTAssemblyLoader/ACTAssemblyLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using Advanced_Combat_Tracker;

namespace ACTAssemblyLoader
{
public partial class ACTAssemblyLoader : IActPluginV1
{
Label lblStatus; // The status label that appears in ACT's Plugin tab
string settingsFile = Path.Combine(ActGlobals.oFormActMain.AppDataFolder.FullName, "Config\\ACTAssemblyLoader.config.xml");
SettingsSerializer xmlSettings;

public ACTAssemblyLoader()
{
InitializeComponent();
}

public void DeInitPlugin()
{
SaveSettings();
lblStatus.Text = "Plugin Exited";
}

public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText)
{
lblStatus = pluginStatusText; // Hand the status label's reference to our local var
pluginScreenSpace.Controls.Add(this); // Add this UserControl to the tab ACT provides
this.Dock = DockStyle.Fill; // Expand the UserControl to fill the tab's client space
xmlSettings = new SettingsSerializer(this); // Create a new settings serializer and pass it this instance
LoadSettings();

lblStatus.Text = "Plugin Started, loading assemblies...";

foreach (var assembly in textAssemblies.Text.Split(new[] { "\r", "\n", "\r\n" },StringSplitOptions.RemoveEmptyEntries))
{
var tempAssembly = assembly;
lblStatus.Text += Environment.NewLine + "Loading assembly [" + tempAssembly + "]...";
if (!File.Exists(tempAssembly))
{
tempAssembly = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + Path.DirectorySeparatorChar + tempAssembly;
}
Assembly a = Assembly.LoadFile(tempAssembly);
lblStatus.Text += " Loaded assembly, location = " + a.Location;
}
}


void LoadSettings()
{
// Add any controls you want to save the state of
xmlSettings.AddControlSetting(textAssemblies.Name, textAssemblies);

if (File.Exists(settingsFile))
{
FileStream fs = new FileStream(settingsFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
XmlTextReader xReader = new XmlTextReader(fs);

try
{
while (xReader.Read())
{
if (xReader.NodeType == XmlNodeType.Element)
{
if (xReader.LocalName == "SettingsSerializer")
{
xmlSettings.ImportFromXml(xReader);
}
}
}
}
catch (Exception ex)
{
lblStatus.Text = "Error loading settings: " + ex.Message;
}
xReader.Close();
}
}
void SaveSettings()
{
FileStream fs = new FileStream(settingsFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
XmlTextWriter xWriter = new XmlTextWriter(fs, Encoding.UTF8);
xWriter.Formatting = Formatting.Indented;
xWriter.Indentation = 1;
xWriter.IndentChar = '\t';
xWriter.WriteStartDocument(true);
xWriter.WriteStartElement("Config"); // <Config>
xWriter.WriteStartElement("SettingsSerializer"); // <Config><SettingsSerializer>
xmlSettings.ExportToXml(xWriter); // Fill the SettingsSerializer XML
xWriter.WriteEndElement(); // </SettingsSerializer>
xWriter.WriteEndElement(); // </Config>
xWriter.WriteEndDocument(); // Tie up loose ends (shouldn't be any)
xWriter.Flush(); // Flush the file buffer to disk
xWriter.Close();
}
}
}
64 changes: 64 additions & 0 deletions ACTAssemblyLoader/ACTAssemblyLoader.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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>{8DEF8763-7845-4364-B9D9-CE2C9DA5CE6C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ACTAssemblyLoader</RootNamespace>
<AssemblyName>ACTAssemblyLoader</AssemblyName>
<TargetFrameworkVersion>v4.6.1</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="Advanced Combat Tracker">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Advanced Combat Tracker\Advanced Combat Tracker.exe</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<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" />
</ItemGroup>
<ItemGroup>
<Compile Include="ACTAssemblyLoaderGui.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="ACTAssemblyLoader.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ACTAssemblyLoaderGui.resx">
<DependentUpon>ACTAssemblyLoaderGui.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
85 changes: 85 additions & 0 deletions ACTAssemblyLoader/ACTAssemblyLoaderGui.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ACTAssemblyLoader
{
public partial class ACTAssemblyLoader : UserControl
{
private TextBox textAssemblies;
private Label labelAssemblies;
#region Designer Created Code (Avoid editing)
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Component Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textAssemblies = new System.Windows.Forms.TextBox();
this.labelAssemblies = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// textAssemblies
//
this.textAssemblies.Location = new System.Drawing.Point(7, 20);
this.textAssemblies.Multiline = true;
this.textAssemblies.Name = "textAssemblies";
this.textAssemblies.Size = new System.Drawing.Size(676, 361);
this.textAssemblies.TabIndex = 0;
this.textAssemblies.WordWrap = false;
//
// labelAssemblies
//
this.labelAssemblies.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.labelAssemblies.AutoSize = true;
this.labelAssemblies.Location = new System.Drawing.Point(4, 4);
this.labelAssemblies.Name = "labelAssemblies";
this.labelAssemblies.Size = new System.Drawing.Size(569, 13);
this.labelAssemblies.TabIndex = 1;
this.labelAssemblies.Text = "Place assemblies to load in text box below, one per line. Ensure this plugin load" +
"s first, and restart ACT to apply changes.";
this.labelAssemblies.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// ACTAssemblyLoader
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.labelAssemblies);
this.Controls.Add(this.textAssemblies);
this.Name = "ACTAssemblyLoader";
this.Size = new System.Drawing.Size(686, 384);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

#endregion

}
}
Loading

0 comments on commit b570c27

Please sign in to comment.