issue #2 finds and extracts the defaultProfile from GameData.pak

defaults to the built in xml if the SC version cannot be found
also added some tools to deal with SC directories for later use
Adds Iconic.Zip.Reduced as NuGet package
pull/20/head
bm98 10 years ago
parent 943c4be651
commit 0a4213d113

@ -148,10 +148,17 @@ namespace SCJMapper_V2
/// </summary>
private void InitActionTree( )
{
// default profile handling
// TODO ?? change the data path away from the app directory as this is not Win policy if installed in "Program Files"
String dataPath = "";
SCDefaultProfile SD = new SCDefaultProfile( );
SD.GetDefaultProfile( dataPath );
String defProf = SD.DefaultProfileName; // either "" or a valid full filename
// build TreeView and the ActionMaps
m_AT = new ActionTree( );
m_AT.Ctrl = treeView1; // the ActionTree owns the TreeView control
m_AT.LoadTree( ); // Init
m_AT.LoadTree( defProf ); // Init with default profile filepath
// default JS to Joystick mapping - can be changed and reloaded from XML
if ( tc1.TabCount > 0 ) { cbJs1.SelectedIndex = 0; m_AT.ActionMaps.js1 = cbJs1.Text; }

@ -15,7 +15,7 @@ namespace SCJMapper_V2
// Load MappingVars.csv into the ActionList and create the Control TreeView
public void LoadTree( )
public void LoadTree( String defaultProfile )
{
TreeNode tn = null;
TreeNode[] cnl = { };
@ -33,14 +33,24 @@ namespace SCJMapper_V2
DProfileReader dpReader = new DProfileReader( ); // we may read a profile
TextReader txReader = null;
// 1st choice is a user given MappingVars.csv file in the appdir
// 1st choice is a user given MappingVars.csv file in the appdir - this is only compatibilty and testing
if ( File.Exists( "MappingVars.csv" ) ) {
txReader = new StreamReader( "MappingVars.csv" );
}
// second choice a defaultProfile.xml in the app dir
// second choice a defaultProfile.xml in given path
else if ( File.Exists( defaultProfile ) ) {
using ( StreamReader sr = new StreamReader( defaultProfile ) ) {
String buff = sr.ReadToEnd( );
dpReader.fromXML( buff );
}
if ( dpReader.ValidContent ) {
txReader = new StringReader( dpReader.CSVMap );
}
}
// third choice a defaultProfile.xml in the app dir distributed with the application ??? to be deleted ???
else {
if ( File.Exists( "defaultProfile.xml" ) ) {
using ( StreamReader sr = new StreamReader( "defaultProfile.xml" ) ) {
if ( File.Exists( SCPath.DefaultProfileName ) ) {
using ( StreamReader sr = new StreamReader( SCPath.DefaultProfileName ) ) {
String buff = sr.ReadToEnd( );
dpReader.fromXML( buff );
}
@ -78,7 +88,7 @@ namespace SCJMapper_V2
}
}//for
tn = new TreeNode( acm.name, cnl ); tn.Name = acm.name; // name it to find it..
tn.ImageIndex = 0; tn.NodeFont = new Font( Ctrl.Font, FontStyle.Bold );
tn.ImageIndex = 0; tn.NodeFont = new Font( Ctrl.Font, FontStyle.Bold );
Ctrl.BackColor = Ctrl.BackColor; // fix for defect TreeView (cut off bold text)
Ctrl.Nodes.Add( tn ); // add to control
if ( topNode == null ) topNode = tn; // once to keep the start of list
@ -203,7 +213,7 @@ namespace SCJMapper_V2
if ( !String.IsNullOrEmpty( ActionMaps.js6 ) ) repList += String.Format( "** js6 = {0}\n", ActionMaps.js6 );
if ( !String.IsNullOrEmpty( ActionMaps.js7 ) ) repList += String.Format( "** js7 = {0}\n", ActionMaps.js7 );
if ( !String.IsNullOrEmpty( ActionMaps.js8 ) ) repList += String.Format( "** js8 = {0}\n", ActionMaps.js8 );
repList += String.Format( "\n");
repList += String.Format( "\n" );
foreach ( ActionMapCls acm in ActionMaps ) {
String rep = String.Format( "*** {0}\n", acm.name );
repList += rep;

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<DirectedGraph GraphDirection="LeftToRight" xmlns="http://schemas.microsoft.com/vs/2009/dgml">
<Nodes>
<Node Id="SCJMapper-V2" Label="SCJMapper-V2" Category="Project" />
<Node Id="SharpDX 2.6.2" Label="SharpDX 2.6.2" Category="Package" />
<Node Id="SharpDX.DirectInput 2.6.2" Label="SharpDX.DirectInput 2.6.2" Category="Package" />
</Nodes>
<Links>
<Link Source="SharpDX.DirectInput 2.6.2" Target="SharpDX 2.6.2" Category="Package Dependency" />
<Link Source="SCJMapper-V2" Target="SharpDX.DirectInput 2.6.2" Category="Installed Package" />
</Links>
<Categories>
<Category Id="Project" />
<Category Id="Package" />
</Categories>
<Styles>
<Style TargetType="Node" GroupLabel="Project" ValueLabel="True">
<Condition Expression="HasCategory('Project')" />
<Setter Property="Background" Value="Blue" />
</Style>
<Style TargetType="Link" GroupLabel="Package Dependency" ValueLabel="True">
<Condition Expression="HasCategory('Package Dependency')" />
<Setter Property="Background" Value="Yellow" />
</Style>
</Styles>
</DirectedGraph>

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ionic.Zip;
using System.IO;
namespace SCJMapper_V2
{
/// <summary>
/// Finds and returns the DefaultProfile from SC GameData.pak
/// it is located in GameData.pak \Libs\Config
/// </summary>
class SCDefaultProfile
{
private Boolean m_valid = false;
public Boolean IsValid { get { return m_valid; } }
private String m_fileName = "";
public String DefaultProfileName { get { return m_fileName; } }
/// <summary>
/// Extracts the file to destPath
/// the subpath will be retained
/// </summary>
/// <param name="destPath">Destination path to extract to</param>
private void ExtractDefaultProfile( String destPath )
{
String scp = SCPath.SCClientDataPath;
if ( String.IsNullOrEmpty( scp ) ) return; // sorry did not work
using ( ZipFile zip = ZipFile.Read( SCPath.SCGameData_pak ) ) {
zip.CaseSensitiveRetrieval = false;
ICollection<ZipEntry> gdpak = zip.SelectEntries( "name = " + SCPath.DefaultProfileName, SCPath.DefaultProfilePath_rel );
if ( gdpak != null ) {
gdpak.FirstOrDefault( ).Extract( destPath, ExtractExistingFileAction.OverwriteSilently );
m_fileName = Path.Combine( destPath, SCPath.DefaultProfilePath_rel );
m_fileName = Path.Combine( m_fileName, SCPath.DefaultProfileName );
m_valid = true;
}
}
}
/// <summary>
/// Deletes the extracted version of the defaultProfile
/// </summary>
/// <param name="destPath">Destination path to delete from</param>
public void ClearDefaultProfile( String destPath )
{
try {
String p = Path.Combine( destPath, SCPath.DefaultProfilePath_rel );
File.Delete( Path.Combine( p, SCPath.DefaultProfileName ) );
m_fileName = "";
m_valid = false;
}
catch { }
}
/// <summary>
/// Retrieves the newest defaultProfile from GameData.pak
/// It deletes the last retrieved one first
/// </summary>
/// <param name="destPath">Destination path to extract to</param>
/// <returns>True if successfull; if false there is no old file left in the path</returns>
public Boolean GetDefaultProfile( String destPath )
{
ClearDefaultProfile( destPath );
ExtractDefaultProfile( destPath );
return m_valid;
}
}
}

@ -0,0 +1,156 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Win32;
namespace SCJMapper_V2
{
/// <summary>
/// Find the SC pathes and folders
/// </summary>
class SCPath
{
/// <summary>
/// Try to locate the launcher under "App Paths"
/// </summary>
static private String SCLauncherPath1
{
get
{
String scpath = ( String )Registry.GetValue( @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths\StarCitizen Launcher.exe", "", null );
if ( scpath != null ) {
return scpath;
}
return "";
}
}
/// <summary>
/// Try to locate the launcher under "Uninstall"
/// </summary>
static private String SCLauncherPath2
{
get
{
String scpath = ( String )Registry.GetValue( @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\StarCitizen", "DisplayIcon", null );
if ( scpath != null ) {
return scpath;
}
return "";
}
}
/// <summary>
/// Returns the base SC install path from something like "E:\G\StarCitizen\Launcher\StarCitizenLauncher.exe"
/// </summary>
static private String SCBasePath
{
get
{
String scp = SCLauncherPath1;
if ( String.IsNullOrEmpty( scp ) ) {
scp = SCLauncherPath2;
if ( String.IsNullOrEmpty( scp ) ) {
return ""; // sorry did not found a thing..
}
}
// found the launcher
scp = Path.GetDirectoryName( scp ); // "E:\G\StarCitizen\Launcher"
scp = Path.GetDirectoryName( scp ); // "E:\G\StarCitizen"
return scp;
}
}
/// <summary>
/// Returns the SC installation path
/// </summary>
static public String SCInstallPath
{
get
{
return SCBasePath;
}
}
/// <summary>
/// Returns the SC ClientData path e.g. "E:\G\StarCitizen\CitizenClient\Data"
/// </summary>
static public String SCClientDataPath
{
get
{
String scp = SCBasePath;
if ( String.IsNullOrEmpty( scp ) ) return "";
//
scp = Path.Combine( scp, "CitizenClient" );
scp = Path.Combine( scp, "Data" );
return scp;
}
}
/// <summary>
/// Returns the SC ClientData path e.g. "E:\G\StarCitizen\CitizenClient\USER"
/// </summary>
static public String SCClientUSERPath
{
get
{
String scp = SCBasePath;
if ( String.IsNullOrEmpty( scp ) ) return "";
//
scp = Path.Combine( scp, "CitizenClient" );
scp = Path.Combine( scp, "USER" );
return scp;
}
}
/// <summary>
/// Returns the SC GameData.pak file path e.g. "E:\G\StarCitizen\CitizenClient\Data\GameData.pak"
/// </summary>
static public String SCGameData_pak
{
get
{
String scp = SCClientDataPath;
if ( String.IsNullOrEmpty( scp ) ) return "";
//
scp = Path.Combine( scp, "GameData.pak" );
return scp;
}
}
/// <summary>
/// Returns the relative path of DefaultProfile.xml
/// </summary>
static public String DefaultProfilePath_rel
{
get
{
return @"Libs\Config";
}
}
/// <summary>
/// Returns the name of the DefaultProfile.xml
/// </summary>
static public String DefaultProfileName
{
get
{
return @"defaultProfile.xml";
}
}
}
}

@ -42,6 +42,9 @@
<StartupObject>SCJMapper_V2.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Ionic.Zip.Reduced">
<HintPath>packages\DotNetZip.Reduced.1.9.1.8\lib\net20\Ionic.Zip.Reduced.dll</HintPath>
</Reference>
<Reference Include="SharpDX">
<HintPath>$(SharpDXPackageBinDir)\SharpDX.dll</HintPath>
</Reference>
@ -81,6 +84,8 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SC\SCDefaultProfile.cs" />
<Compile Include="SC\SCPath.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetZip.Reduced" version="1.9.1.8" targetFramework="net40" />
<package id="SharpDX" version="2.6.2" targetFramework="net20" />
<package id="SharpDX.DirectInput" version="2.6.2" targetFramework="net40" />
</packages>
Loading…
Cancel
Save