Cleanup the DefaultProfile capture

pull/20/head
bm98 10 years ago
parent 0a4213d113
commit ee62bddf08

@ -148,17 +148,10 @@ 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( defProf ); // Init with default profile filepath
m_AT.LoadTree( ); // 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( String defaultProfile )
public void LoadTree( )
{
TreeNode tn = null;
TreeNode[] cnl = { };
@ -33,36 +33,9 @@ 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 - this is only compatibilty and testing
if ( File.Exists( "MappingVars.csv" ) ) {
txReader = new StreamReader( "MappingVars.csv" );
}
// 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( SCPath.DefaultProfileName ) ) {
using ( StreamReader sr = new StreamReader( SCPath.DefaultProfileName ) ) {
String buff = sr.ReadToEnd( );
dpReader.fromXML( buff );
}
if ( dpReader.ValidContent ) {
txReader = new StringReader( dpReader.CSVMap );
}
}
}
// last resort is the built in list
if ( txReader == null ) {
var defFile = SCJMapper_V2.Properties.Resources.MappingVars;
txReader = new StringReader( defFile );
dpReader.fromXML( SCDefaultProfile.DefaultProfile( ) );
if ( dpReader.ValidContent ) {
txReader = new StringReader( dpReader.CSVMap );
}
using ( TextReader sr = txReader ) {

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34014
// Runtime Version:4.0.30319.18444
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@ -71,12 +71,26 @@ namespace SCJMapper_V2.Properties {
}
/// <summary>
/// Looks up a localized string similar to spaceship_general;Kv_toggle_cabin_lights;Kv_toggle_running_lights;Kv_power_cycle_preset_fwd;Kv_power_cycle_preset_back;Xv_eject;;;;;;;;;;;;;;;;;;;;;;;
///spaceship_view;Jv_view_yaw_left;Jv_view_yaw_right;Jv_view_yaw;Jv_view_yaw_1p;Kv_view_yaw_absolute;Jv_view_pitch_up;Jv_view_pitch_down;Jv_view_pitch;Jv_view_pitch_1p;Kv_view_pitch_absolute;Kv_view_roll_absolute;Jv_view_cycle_fwd;Kv_view_cycle_internal_fwd;Xv_view_option;Xv_view_mode;Jv_view_zoom_in;Jv_view_zoom_out;Kv_view_dynamic_focus_in;Kv_view_dynamic_foc [rest of string was truncated]&quot;;.
/// Looks up a localized string similar to &lt;profile version=&quot;0&quot;&gt;
/// &lt;platforms&gt;
/// &lt;PC keyboard=&quot;1&quot; xboxpad=&quot;1&quot; ps3pad=&quot;1&quot; joystick=&quot;1&quot; /&gt;
/// &lt;Xbox keyboard=&quot;1&quot; xboxpad=&quot;1&quot; ps3pad=&quot;0&quot; /&gt;
/// &lt;PS3 keyboard=&quot;1&quot; xboxpad=&quot;0&quot; ps3pad=&quot;1&quot; /&gt;
/// &lt;/platforms&gt;
///
/// &lt;actiongroup action=&quot;v_attack1&quot;&gt;
/// &lt;action name=&quot;v_attack1_group1&quot; /&gt;
/// &lt;action name=&quot;v_attack1_group2&quot; /&gt;
/// &lt;action name=&quot;v_attack1_group3&quot; /&gt;
/// &lt;/actiongroup&gt;
///
/// &lt;actionmap name=&quot;debug&quot; version=&quot;22&quot;&gt;
/// &lt;!-- debug keys - move to debug when we can switch devmode--&gt;
/// &lt;action name=&quot;flymode&quot; onPres [rest of string was truncated]&quot;;.
/// </summary>
internal static string MappingVars {
internal static string defaultProfile {
get {
return ResourceManager.GetString("MappingVars", resourceCulture);
return ResourceManager.GetString("defaultProfile", resourceCulture);
}
}
}

@ -121,7 +121,7 @@
<data name="Cassini_Logo2_s" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\graphics\Cassini_Logo2_s.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="MappingVars" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\actionList\MappingVars.csv;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
<data name="defaultProfile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\defaultprofile.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
</root>

@ -14,63 +14,54 @@ namespace SCJMapper_V2
/// </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 )
static public String DefaultProfile( )
{
String scp = SCPath.SCClientDataPath;
if ( String.IsNullOrEmpty( scp ) ) return; // sorry did not work
String retVal = "";
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;
// first try to get the SC defaultProfile from the GameData.pak
retVal = ExtractDefaultProfile( );
if ( String.IsNullOrEmpty( retVal ) ) {
// second choice a defaultProfile.xml in the app dir distributed with the application ??? to be deleted ???
if ( File.Exists( SCPath.DefaultProfileName ) ) {
using ( StreamReader sr = new StreamReader( SCPath.DefaultProfileName ) ) {
retVal = sr.ReadToEnd( );
}
}
// last resort is the built in one
else {
retVal = SCJMapper_V2.Properties.Resources.defaultProfile;
}
}
return retVal;
}
/// <summary>
/// Deletes the extracted version of the defaultProfile
/// Extracts the file to the internal string
/// </summary>
/// <param name="destPath">Destination path to delete from</param>
public void ClearDefaultProfile( String destPath )
static private String ExtractDefaultProfile( )
{
try {
String p = Path.Combine( destPath, SCPath.DefaultProfilePath_rel );
File.Delete( Path.Combine( p, SCPath.DefaultProfileName ) );
m_fileName = "";
m_valid = false;
String retVal = "";
if ( File.Exists( SCPath.SCGameData_pak ) ) {
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 ) {
try {
MemoryStream mst = new MemoryStream( );
gdpak.FirstOrDefault( ).Extract( mst );
UTF8Encoding unc = new UTF8Encoding( );
retVal = unc.GetString( mst.ToArray( ) );
}
catch {
retVal = ""; // clear any remanents
}
}
}
}
catch { }
return retVal;
}
/// <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;
}
}
}

Loading…
Cancel
Save