Add log4net instrumentation (Win 8.1 seems to make still problems)

Compiled for AnyCPU
pull/20/head
bm98 10 years ago
parent d924956508
commit 8371532108

@ -15,7 +15,9 @@ namespace SCJMapper_V2
{
public partial class MainForm : Form
{
private const String c_GithubLink = "https://github.com/bm98/SCJMapper-V2/releases";
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
private const String c_GithubLink = @"https://github.com/SCToolsfactory/SCJMapper-V2/releases";
private AppSettings m_AppSettings = new AppSettings( );
@ -63,42 +65,53 @@ namespace SCJMapper_V2
/// <param name="e"></param>
private void MainForm_Load( object sender, System.EventArgs e )
{
log.Debug( "MainForm_Load - Entry" );
// some applic initialization
// Assign Size property, since databinding to Size doesn't work well.
this.Size = m_AppSettings.FormSize;
this.Location = m_AppSettings.FormLocation;
// XML RTB
rtb.SelectionTabs = new int[] { 10, 20, 30, 40, 50, 60 }; // short tabs
rtb.DragEnter += new DragEventHandler( rtb_DragEnter );
rtb.DragDrop += new DragEventHandler( rtb_DragDrop );
rtb.AllowDrop = true; // add Drop to rtb
String version = Application.ProductVersion; // get the version information
lblTitle.Text += " - V " + version.Substring( 0, version.IndexOf( ".", version.IndexOf( "." ) + 1 ) ); // get the first two elements
// tooltips where needed
toolTip1.SetToolTip( this.linkLblReleases, c_GithubLink ); // allow to see where the link may head
// XML RTB
log.Debug( "Loading RTB" );
rtb.SelectionTabs = new int[] { 10, 20, 30, 40, 50, 60 }; // short tabs
rtb.DragEnter += new DragEventHandler( rtb_DragEnter );
rtb.DragDrop += new DragEventHandler( rtb_DragDrop );
rtb.AllowDrop = true; // add Drop to rtb
// load profiles
log.Debug( "Loading Profiles" );
foreach ( String s in SCDefaultProfile.DefaultProfileNames ) {
tsDDbtProfiles.DropDownItems.Add( Path.GetFileNameWithoutExtension( s ) );
}
tsDDbtProfiles.Text = m_AppSettings.DefProfileName;
// load mappings
log.Debug( "Loading Mappings" );
LoadMappingDD( );
tsDDbtMappings.Text = m_AppSettings.DefMappingName;
// load other defaults
log.Debug( "Loading Other" );
txMappingName.Text = m_AppSettings.MyMappingName;
SetRebindField( txMappingName.Text );
// Init X things
if ( !InitDirectInput( ) )
log.Debug( "Loading DirectX" );
if ( !InitDirectInput( ) ) {
log.Fatal( "Initializing DirectXInput failed" );
MessageBox.Show( "Initializing DirectXInput failed - program exits now", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Information );
Close( );
}
log.Debug( "Loading last used mapping" );
if ( SCMappings.MappingFileExists( txMappingName.Text ) ) {
rtb.LoadFile( SCMappings.MappingFileName( txMappingName.Text ), RichTextBoxStreamType.PlainText );
InitActionTree( false );
@ -107,10 +120,12 @@ namespace SCJMapper_V2
txMappingName.BackColor = MyColors.SuccessColor;
}
else {
log.WarnFormat( "Last used mapping not available ({0})", txMappingName.Text );
txMappingName.BackColor = MyColors.ErrorColor;
}
// poll the XInput
log.Debug( "Start XInput polling" );
timer1.Start( ); // this one polls the joysticks to show the props
}
@ -120,6 +135,7 @@ namespace SCJMapper_V2
/// </summary>
private void buttonExit_Click( object sender, System.EventArgs e )
{
log.Debug( "Shutting down now..." );
Close( );
}
@ -182,8 +198,8 @@ namespace SCJMapper_V2
}
}
catch ( Exception Ex ) {
log.Error( "Ex DrawItem", Ex );
MessageBox.Show( Ex.Message.ToString( ), "Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Information );
}
}
@ -195,6 +211,8 @@ namespace SCJMapper_V2
/// </summary>
private void InitActionTree( Boolean addDefaultBinding )
{
log.Debug( "InitActionTree - Entry" );
// build TreeView and the ActionMaps
m_AT = new ActionTree( );
m_AT.Ctrl = treeView1; // the ActionTree owns the TreeView control
@ -206,65 +224,86 @@ namespace SCJMapper_V2
if ( tc1.TabCount > 2 ) { cbJs3.SelectedIndex = 2; m_AT.ActionMaps.js3 = cbJs3.Text; }
}
/// <summary>
/// Aquire the DInput joystick devices
/// </summary>
/// <returns></returns>
public bool InitDirectInput( )
{
log.Debug( "Entry" );
// Enumerate joysticks in the system.
int tabs = 0;
cbJs1.Items.Clear( ); cbJs2.Items.Clear( ); cbJs3.Items.Clear( ); // JS dropdowns init
// Initialize DirectInput
var directInput = new DirectInput( );
try {
// Initialize DirectInput
log.Debug( "Instantiate DirectInput" );
var directInput = new DirectInput( );
// scan the Input for attached devices
log.Debug( "Scan GameControl devices" );
foreach ( DeviceInstance instance in directInput.GetDevices( DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly ) ) {
// Create the device interface
log.Debug( "Create the device interface" );
Joystick jsDevice = new Joystick( directInput, instance.InstanceGuid );
JoystickCls js = null;
log.DebugFormat( "Create the device interface for: {0}", jsDevice.Information.ProductName );
// we have the first tab made as reference so TabPage[0] already exists
if ( tabs == 0 ) {
// first panel - The Tab content exists already
log.Debug( "Add first Joystick panel" );
js = new JoystickCls( jsDevice, this, UC_JoyPanel ); // does all device related activities for that particular item
}
else {
log.Debug( "Add next Joystick panel" );
// setup the further tab contents along the reference one in TabPage[0] (the control named UC_JoyPanel)
tc1.TabPages.Add( "Joystick " + ( tabs + 1 ).ToString( ) );
UC_JoyPanel uUC_JoyPanelNew = new UC_JoyPanel( );
tc1.TabPages[tabs].Controls.Add( uUC_JoyPanelNew );
uUC_JoyPanelNew.Size = UC_JoyPanel.Size;
uUC_JoyPanelNew.Location = UC_JoyPanel.Location;
log.Debug( "Create Joystick instance" );
js = new JoystickCls( jsDevice, this, uUC_JoyPanelNew ); // does all device related activities for that particular item
}
m_JS.Add( js ); // add to joystick list
// scan the Input for attached devices
foreach ( DeviceInstance instance in directInput.GetDevices( DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly ) ) {
tc1.TabPages[tabs].Tag = js.DevName; // used to find the tab via JS mapping
tc1.TabPages[tabs].BackColor = MyColors.JColor[tabs]; // each tab has its own color
cbJs1.Items.Add( js.DevName ); cbJs2.Items.Add( js.DevName ); cbJs3.Items.Add( js.DevName ); // populate DropDowns with the JS name
// Create the device interface
Joystick jsDevice = new Joystick( directInput, instance.InstanceGuid );
JoystickCls js = null;
// next tab
tabs++;
if ( tabs == 8 ) break; // cannot load more JSticks than predefined Tabs
}
log.DebugFormat( "Added {0} GameControl devices", tabs );
// we have the first tab made as reference so TabPage[0] already exists
if ( tabs == 0 ) {
// first panel - The Tab content exists already
js = new JoystickCls( jsDevice, this, UC_JoyPanel ); // does all device related activities for that particular item
/*
// TEST CREATE ALL 8 TABS
for ( int i=(tabs+1); i < 9; i++ ) {
tc1.TabPages.Add( "Joystick " + i.ToString( ) );
}
else {
// setup the further tab contents along the reference one in TabPage[0] (the control named UC_JoyPanel)
tc1.TabPages.Add( "Joystick " + ( tabs + 1 ).ToString( ) );
UC_JoyPanel uUC_JoyPanelNew = new UC_JoyPanel( );
tc1.TabPages[tabs].Controls.Add( uUC_JoyPanelNew );
uUC_JoyPanelNew.Size = UC_JoyPanel.Size;
uUC_JoyPanelNew.Location = UC_JoyPanel.Location;
js = new JoystickCls( jsDevice, this, uUC_JoyPanelNew ); // does all device related activities for that particular item
*/
if ( tabs == 0 ) {
log.Warn( "Unable to find and/or create any joystick devices." );
MessageBox.Show( "Unable to create a joystick device. Program will exit.", "No joystick found", MessageBoxButtons.OK, MessageBoxIcon.Information );
return false;
}
m_JS.Add( js ); // add to joystick list
tc1.TabPages[tabs].Tag = js.DevName; // used to find the tab via JS mapping
tc1.TabPages[tabs].BackColor = MyColors.JColor[tabs]; // each tab has its own color
cbJs1.Items.Add( js.DevName ); cbJs2.Items.Add( js.DevName ); cbJs3.Items.Add( js.DevName ); // populate DropDowns with the JS name
// load the profile items from the XML
log.Debug( "Init ActionTree" );
InitActionTree( true );
// next tab
tabs++;
if ( tabs == 8 ) break; // cannot load more JSticks than predefined Tabs
}
/*
// TEST CREATE ALL 8 TABS
for ( int i=(tabs+1); i < 9; i++ ) {
tc1.TabPages.Add( "Joystick " + i.ToString( ) );
}
*/
if ( tabs == 0 ) {
MessageBox.Show( "Unable to create a joystick device. Program will exit.", "No joystick found" );
catch ( Exception ex ) {
log.Debug( "InitDirectInput failed unexpetedly", ex );
return false;
}
// load the profile items from the XML
InitActionTree( true );
return true;
}
@ -289,6 +328,8 @@ namespace SCJMapper_V2
/// </summary>
private void Grab( )
{
log.Debug( "Grab - Entry" );
m_AT.ActionMaps.fromXML( rtb.Text );
m_AT.ReloadCtrl( );
// JS mapping for the first 3 items can be changed and reloaded from XML
@ -314,6 +355,8 @@ namespace SCJMapper_V2
/// </summary>
private void Dump( )
{
log.Debug( "Dump - Entry" );
rtb.Text = String.Format( "<!-- {0} - SC Joystick Mapping -->\n{1}", DateTime.Now, m_AT.ActionMaps.toXML( ) );
btDump.BackColor = btClear.BackColor; btDump.UseVisualStyleBackColor = btClear.UseVisualStyleBackColor; // neutral again
@ -333,6 +376,8 @@ namespace SCJMapper_V2
private void MainForm_FormClosing( object sender, FormClosingEventArgs e )
{
log.Debug( "MainForm_FormClosing - Entry" );
m_AppSettings.FormSize = this.Size;
m_AppSettings.FormLocation = this.Location;
m_AppSettings.Save( );

@ -15,6 +15,8 @@ namespace SCJMapper_V2
/// </summary>
class ActionCls
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
// Static items to have this mapping in only one place
/// <summary>

@ -20,6 +20,7 @@ namespace SCJMapper_V2
/// </summary>
class ActionMapCls : List<ActionCls>
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
public String name { get; set; }

@ -20,6 +20,9 @@ namespace SCJMapper_V2
/// </summary>
class ActionMapsCls : List<ActionMapCls>
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
public String version { get; set; }
// own additions for JS mapping - should not harm..
public String js1 { get; set; }
@ -47,6 +50,8 @@ namespace SCJMapper_V2
/// <param name="newAcm"></param>
private void Merge( ActionMapCls newAcm )
{
log.Debug( "Merge - Entry" );
// do we find an actionmap like the new one in our list ?
ActionMapCls ACM = this.Find( delegate( ActionMapCls acm ) {
return acm.name == newAcm.name;
@ -66,7 +71,9 @@ namespace SCJMapper_V2
/// <returns>the action as XML fragment</returns>
public String toXML( )
{
String r = String.Format( "<ActionMaps version=\"{0}\" ", version);
log.Debug( "toXML - Entry" );
String r = String.Format( "<ActionMaps version=\"{0}\" ", version );
if ( !String.IsNullOrEmpty( js1 ) ) r += String.Format( "js1=\"{0}\" ", js1 );
if ( !String.IsNullOrEmpty( js2 ) ) r += String.Format( "js2=\"{0}\" ", js2 );
if ( !String.IsNullOrEmpty( js3 ) ) r += String.Format( "js3=\"{0}\" ", js3 );
@ -92,6 +99,8 @@ namespace SCJMapper_V2
/// <returns>True if an action was decoded</returns>
public Boolean fromXML( String xml )
{
log.Debug( "fromXML - Entry" );
XmlReaderSettings settings = new XmlReaderSettings( );
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.IgnoreWhitespace = true;

@ -14,6 +14,7 @@ namespace SCJMapper_V2
/// </summary>
class ActionTree
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
public ActionMapsCls ActionMaps { get; set; } // the Action Maps and Actions
@ -59,6 +60,8 @@ namespace SCJMapper_V2
/// </summary>
private void ApplyFilter( )
{
log.Debug( "ApplyFilter - Entry" );
TreeNode topNode = null; // allow to backup the view - will carry the first node items
Ctrl.BeginUpdate( );
@ -126,6 +129,8 @@ namespace SCJMapper_V2
/// <param name="applyDefaults">True if default mappings should be carried on</param>
public void LoadTree( String defaultProfileName, Boolean applyDefaults )
{
log.Debug( "LoadTree - Entry" );
TreeNode tn = null;
TreeNode[] cnl = { };
TreeNode cn = null;
@ -218,6 +223,8 @@ namespace SCJMapper_V2
/// <param name="input">The new Text property</param>
public void UpdateSelectedItem( String input )
{
log.Debug( "UpdateSelectedItem - Entry" );
if ( Ctrl.SelectedNode == null ) return;
// applies only to ActionNodes
@ -262,6 +269,8 @@ namespace SCJMapper_V2
/// </summary>
public void ReloadCtrl( )
{
log.Debug( "ReloadCtrl - Entry" );
foreach ( ActionMapCls acm in ActionMaps ) {
try {
TreeNode amTn = m_MasterTree.Nodes[acm.name]; // get the map node
@ -303,6 +312,8 @@ namespace SCJMapper_V2
/// <param name="m_MasterTree">The string to find</param>
public void FindCtrl( String ctrl )
{
log.Debug( "FindCtrl - Entry" );
Boolean found = false;
foreach ( TreeNode tn in Ctrl.Nodes ) {
// have to search nodes of nodes
@ -325,6 +336,8 @@ namespace SCJMapper_V2
/// <returns></returns>
public String ReportActions( )
{
log.Debug( "FindCtrl - ReportActions" );
String repList = "";
// JS assignments
if ( !String.IsNullOrEmpty( ActionMaps.js1 ) ) repList += String.Format( "** js1 = {0}\n", ActionMaps.js1 );

@ -11,6 +11,8 @@ namespace SCJMapper_V2
/// </summary>
class DProfileReader
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
public Boolean ValidContent { get; set; }
private Stack<String> m_nodeNameStack = null; // element name stack - keeping track where we are
@ -29,7 +31,7 @@ namespace SCJMapper_V2
public String name { get; set; } // the action name
public String input { get; set; } // the input method K,J,X,P
private String m_defBinding = "";
public String defBinding { get { return m_defBinding;} set { m_defBinding = value.Trim();} } // need to clean this one, found spaces...
public String defBinding { get { return m_defBinding; } set { m_defBinding = value.Trim( ); } } // need to clean this one, found spaces...
public String keyName
{ get { return input + name; } } // prep for TreView usage - create a key from input+name
}
@ -59,6 +61,8 @@ namespace SCJMapper_V2
{
get
{
log.Debug( "CSVMap - Entry" );
String buf = "";
foreach ( ActionMap am in m_aMap.Values ) {
buf += am.name + ";";
@ -266,6 +270,8 @@ namespace SCJMapper_V2
/// <returns></returns>
private Boolean ReadXML( XmlReader xr )
{
log.Debug( "ReadXML - Entry" );
Boolean retVal = true;
try {
@ -295,8 +301,9 @@ namespace SCJMapper_V2
return false;
}
catch {
catch ( Exception ex ) {
// get any exceptions from reading
log.Error( "ReadXML - unexpected", ex );
return false;
}
}
@ -308,6 +315,8 @@ namespace SCJMapper_V2
/// <returns>True if an action was decoded</returns>
public Boolean fromXML( String xml )
{
log.Debug( "fromXML - Entry" );
XmlReaderSettings settings = new XmlReaderSettings( );
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.IgnoreWhitespace = true;

@ -16,6 +16,7 @@ namespace SCJMapper_V2
/// </summary>
class JoystickCls
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
#region Static Items
@ -157,6 +158,8 @@ namespace SCJMapper_V2
/// <param name="panel">The respective JS panel to show the properties</param>
public JoystickCls( Joystick device, Control hwnd, UC_JoyPanel panel )
{
log.DebugFormat( "ctor - Entry with {0}", device.Information.ProductName );
m_device = device;
m_hwnd = hwnd;
m_jPanel = panel;
@ -171,20 +174,26 @@ namespace SCJMapper_V2
m_jPanel.nButtons = ButtonCount.ToString( );
m_jPanel.nPOVs = POVCount.ToString( );
// Set the data format to the c_dfDIJoystick pre-defined format.
//m_device.SetDataFormat( DeviceDataFormat.Joystick );
// Set the cooperative level for the device.
m_device.SetCooperativeLevel( m_hwnd, CooperativeLevel.Exclusive | CooperativeLevel.Foreground );
// Enumerate all the objects on the device.
foreach ( DeviceObjectInstance d in m_device.GetObjects( ) ) {
// For axes that are returned, set the DIPROP_RANGE property for the
// enumerated axis in order to scale min/max values.
if ( ( 0 != ( d.ObjectId.Flags & DeviceObjectTypeFlags.Axis ) ) ) {
// Set the range for the axis.
m_device.Properties.Range = new InputRange( -1000, +1000 );
log.Debug( "Get JS Objects" );
try {
// Set the data format to the c_dfDIJoystick pre-defined format.
//m_device.SetDataFormat( DeviceDataFormat.Joystick );
// Set the cooperative level for the device.
m_device.SetCooperativeLevel( m_hwnd, CooperativeLevel.Exclusive | CooperativeLevel.Foreground );
// Enumerate all the objects on the device.
foreach ( DeviceObjectInstance d in m_device.GetObjects( ) ) {
// For axes that are returned, set the DIPROP_RANGE property for the
// enumerated axis in order to scale min/max values.
if ( ( 0 != ( d.ObjectId.Flags & DeviceObjectTypeFlags.Axis ) ) ) {
// Set the range for the axis.
m_device.Properties.Range = new InputRange( -1000, +1000 );
}
// Update the controls to reflect what objects the device supports.
UpdateControls( d );
}
// Update the controls to reflect what objects the device supports.
UpdateControls( d );
}
catch ( Exception ex ) {
log.Error( "Get JS Objects failed", ex );
}
}
@ -194,8 +203,11 @@ namespace SCJMapper_V2
/// </summary>
public void FinishDX( )
{
if ( null != m_device )
if ( null != m_device ) {
log.DebugFormat( "Release DirectInput device: {0}", m_device.Information.ProductName );
m_device.Unacquire( );
m_device = null;
}
}
@ -414,11 +426,14 @@ namespace SCJMapper_V2
m_device.Acquire( );
}
catch ( SharpDXException ) {
// Failed to acquire the device.
// This could be because the app doesn't have focus.
return;
// Failed to acquire the device. This could be because the app doesn't have focus.
return; // EXIT unaquired
}
}
else {
log.Error( "Unexpected Poll Exception", e );
return; // EXIT see ex code
}
}

@ -2,20 +2,42 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Configuration;
using log4net;
using log4net.Config;
//[assembly: log4net.Config.XmlConfigurator( Watch = true )]
[assembly: log4net.Config.XmlConfigurator( ConfigFile = "log4Net.config", Watch = true )]
namespace SCJMapper_V2
{
static class Program
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger ( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
/* Log Levels Inc Priority
* ALL
* DEBUG
* INFO
* WARN
* ERROR
* FATAL
* OFF
* */
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main( )
{
log.InfoFormat( "\n" );
log.InfoFormat( "SCJMapper_V2 - Started" );
Application.EnableVisualStyles( );
Application.SetCompatibleTextRenderingDefault( false );
Application.Run( new MainForm( ) );
log.InfoFormat( "SCJMapper_V2 - Ended\n" );
}
}
}

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion( "2.0.0.20" )]
[assembly: AssemblyFileVersion( "2.0.0.20" )]
[assembly: AssemblyVersion( "2.1.0.21" )]
[assembly: AssemblyFileVersion( "2.1.0.21" )]

@ -14,6 +14,7 @@ namespace SCJMapper_V2
/// </summary>
class SCDefaultProfile
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
/// <summary>
/// Returns a list of files found that match 'defaultProfile*.xml'
@ -23,16 +24,22 @@ namespace SCJMapper_V2
{
get
{
log.Debug( "DefaultProfileNames - Entry" );
List<String> retVal = new List<String>( );
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 + "*.xml'", SCPath.DefaultProfilePath_rel );
if ( gdpak != null ) {
foreach ( ZipEntry ze in gdpak ) {
retVal.Add( ze.FileName );
try {
zip.CaseSensitiveRetrieval = false;
ICollection<ZipEntry> gdpak = zip.SelectEntries( "name = " + "'" + SCPath.DefaultProfileName + "*.xml'", SCPath.DefaultProfilePath_rel );
if ( gdpak != null ) {
foreach ( ZipEntry ze in gdpak ) {
retVal.Add( ze.FileName );
}
}
}
catch ( Exception ex ) {
log.Error( "Unexpected", ex );
}
}
}
return retVal;
@ -46,47 +53,62 @@ namespace SCJMapper_V2
/// <returns>A string containing the file contents</returns>
static public String DefaultProfile( String defaultProfileName )
{
log.Debug( "DefaultProfile - Entry" );
String retVal = "";
// first try to get the SC defaultProfile from the GameData.pak
retVal = ExtractDefaultProfile( defaultProfileName );
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 + ".xml" ) ) {
using ( StreamReader sr = new StreamReader( SCPath.DefaultProfileName + ".xml" ) ) {
retVal = sr.ReadToEnd( );
}
// first choice a defaultProfile.xml in the app dir distributed with the application ??? to be deleted ???
if ( File.Exists( SCPath.DefaultProfileName + ".xml" ) ) {
using ( StreamReader sr = new StreamReader( SCPath.DefaultProfileName + ".xml" ) ) {
retVal = sr.ReadToEnd( );
log.Info( "- Use AppDirectory defaultProfile" );
}
}
else {
// second try to get the SC defaultProfile from the GameData.pak
retVal = ExtractDefaultProfile( defaultProfileName );
if ( ! String.IsNullOrEmpty( retVal ) ) {
log.Info( "- Use GamePack defaultProfile" );
}
// last resort is the built in one
else {
// last resort is the built in one
retVal = SCJMapper_V2.Properties.Resources.defaultProfile;
log.Info( "- Use built in defaultProfile" );
}
}
return retVal;
}
/// <summary>
/// Zip Extracts the file to a string
/// </summary>
static private String ExtractDefaultProfile( String defaultProfileName )
{
log.Debug( "ExtractDefaultProfile - Entry" );
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 = " + "'" + 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
try {
ICollection<ZipEntry> gdpak = zip.SelectEntries( "name = " + "'" + 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 ( Exception ex ) {
log.Error( "Unexpected", ex );
}
}
}
return retVal;

@ -12,6 +12,9 @@ namespace SCJMapper_V2
/// </summary>
class SCMappings
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
private const String c_UserMapStartsWith = "layout_my_"; // we only allow those mapping names
static private List<String> m_scMappings = new List<string>( );
@ -83,12 +86,16 @@ namespace SCJMapper_V2
{
get
{
log.Debug( "MappingNames - Entry" );
if ( m_scMappings.Count == 0 ) {
if ( Directory.Exists( SCPath.SCClientMappingPath ) ) {
m_scMappings.Clear( );
m_scMappings = ( List<String> )Directory.EnumerateFiles( SCPath.SCClientMappingPath ).ToList( );
}
}
else {
log.Warn( "MappingNames - cannot find SC Mapping directory" );
}
return m_scMappings;
}
}

@ -12,6 +12,7 @@ namespace SCJMapper_V2
/// </summary>
class SCPath
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
/// <summary>
/// Try to locate the launcher under "App Paths"
@ -22,8 +23,10 @@ namespace SCJMapper_V2
{
String scpath = ( String )Registry.GetValue( @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths\StarCitizen Launcher.exe", "", null );
if ( scpath != null ) {
log.Info( "SCLauncherPath1 - Found HKLM - AppPath - Launcher.exe" );
return scpath;
}
log.Warn( "SCLauncherPath1 - did not found HKLM - AppPath - Launcher.exe" );
return "";
}
}
@ -37,8 +40,10 @@ namespace SCJMapper_V2
{
String scpath = ( String )Registry.GetValue( @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\StarCitizen", "DisplayIcon", null );
if ( scpath != null ) {
log.Info( "SCLauncherPath2 - Found HKLM - Uninstall - StarCitizen" );
return scpath;
}
log.Warn( "SCLauncherPath2 - did not found HKLM - Uninstall - StarCitizen" );
return "";
}
}
@ -51,6 +56,7 @@ namespace SCJMapper_V2
{
get
{
log.Debug( "SCBasePath - Entry" );
String scp = SCLauncherPath1;
if ( String.IsNullOrEmpty( scp ) ) {
scp = SCLauncherPath2;
@ -74,6 +80,7 @@ namespace SCJMapper_V2
{
get
{
log.Debug( "SCInstallPath - Entry" );
return SCBasePath;
}
}
@ -86,6 +93,7 @@ namespace SCJMapper_V2
{
get
{
log.Debug( "SCClientDataPath - Entry" );
String scp = SCBasePath;
if ( String.IsNullOrEmpty( scp ) ) return "";
//
@ -103,6 +111,7 @@ namespace SCJMapper_V2
{
get
{
log.Debug( "SCClientUSERPath - Entry" );
String scp = SCBasePath;
if ( String.IsNullOrEmpty( scp ) ) return "";
//
@ -120,6 +129,7 @@ namespace SCJMapper_V2
{
get
{
log.Debug( "SCClientMappingPath - Entry" );
String scp = SCClientDataPath;
if ( String.IsNullOrEmpty( scp ) ) return "";
//
@ -137,6 +147,7 @@ namespace SCJMapper_V2
{
get
{
log.Debug( "SCGameData_pak - Entry" );
String scp = SCClientDataPath;
if ( String.IsNullOrEmpty( scp ) ) return "";
//
@ -153,6 +164,7 @@ namespace SCJMapper_V2
{
get
{
log.Debug( "DefaultProfilePath_rel - Entry" );
return @"Libs\Config";
}
}
@ -164,6 +176,7 @@ namespace SCJMapper_V2
{
get
{
log.Debug( "DefaultProfileName - Entry" );
return @"defaultProfile";
}
}

@ -26,8 +26,8 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>20</ApplicationRevision>
<ApplicationVersion>2.0.0.%2a</ApplicationVersion>
<ApplicationRevision>21</ApplicationRevision>
<ApplicationVersion>2.1.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
@ -56,10 +56,34 @@
<PropertyGroup>
<StartupObject>SCJMapper_V2.Program</StartupObject>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
</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="log4net">
<HintPath>packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
</Reference>
<Reference Include="SharpDX">
<HintPath>$(SharpDXPackageBinDir)\SharpDX.dll</HintPath>
</Reference>
@ -125,6 +149,9 @@
<None Include="actionList\MappingVars.csv" />
<None Include="actionList\MappingVars.xlsx" />
<None Include="app.config" />
<None Include="log4net.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
@ -137,8 +164,8 @@
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="defaultProfile.xml" />
<Content Include="Cassini_Logo_Icon.ico" />
<Content Include="defaultProfile.xml" />
<Content Include="graphics\Cassini_Logo2_s.jpg" />
<Content Include="graphics\Cassini_Logo_Icon.ico" />
<Content Include="graphics\invalid.png" />

@ -5,14 +5,20 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SCJMapper-V2", "SCJMapper-V
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B5F8B339-E02E-4F6D-BF62-D776F165910F}.Debug|x86.ActiveCfg = Debug|x86
{B5F8B339-E02E-4F6D-BF62-D776F165910F}.Debug|x86.Build.0 = Debug|x86
{B5F8B339-E02E-4F6D-BF62-D776F165910F}.Release|x86.ActiveCfg = Release|x86
{B5F8B339-E02E-4F6D-BF62-D776F165910F}.Release|x86.Build.0 = Release|x86
{B5F8B339-E02E-4F6D-BF62-D776F165910F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5F8B339-E02E-4F6D-BF62-D776F165910F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5F8B339-E02E-4F6D-BF62-D776F165910F}.Debug|x86.ActiveCfg = Debug|Any CPU
{B5F8B339-E02E-4F6D-BF62-D776F165910F}.Debug|x86.Build.0 = Debug|Any CPU
{B5F8B339-E02E-4F6D-BF62-D776F165910F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5F8B339-E02E-4F6D-BF62-D776F165910F}.Release|Any CPU.Build.0 = Release|Any CPU
{B5F8B339-E02E-4F6D-BF62-D776F165910F}.Release|x86.ActiveCfg = Release|Any CPU
{B5F8B339-E02E-4F6D-BF62-D776F165910F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -12,6 +12,7 @@ namespace SCJMapper_V2
/// </summary>
class TheUser
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
/// <summary>
/// Returns the name of the Personal Program folder in My Documents
@ -22,6 +23,7 @@ namespace SCJMapper_V2
{
get
{
log.Debug( "UserDir - Entry" );
String docPath = Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.Personal ), Application.ProductName);
if ( !Directory.Exists( docPath ) ) Directory.CreateDirectory( docPath );
return docPath;
@ -36,6 +38,8 @@ namespace SCJMapper_V2
/// <returns>A fully qualified filename</returns>
static public String MappingFileName( String mapName )
{
log.Debug( "MappingFileName - Entry" );
return Path.Combine( UserDir, mapName + ".xml" );
}

@ -2,7 +2,6 @@
<configuration>
<configSections>
<section name="AppConfiguration"
type="SCJMapper_V2.AppConfiguration, SCJMapper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" restartOnExternalChanges="true" />
@ -15,5 +14,4 @@
<!-- This is the minimal change that detects a movement of an axis
default is 150 - you may change it to get the detection less sensitive -->
<AppConfiguration jsSenseLimit="150" />
</configuration>

@ -0,0 +1,34 @@
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="trace.log"/>
<!--Indicates whether the file should be appended to or overwritten.-->
<appendToFile value="true"/>
<!--Roll files based only on the size of the file-->
<rollingStyle value="Size"/>
<!--The maximum number of backup files that are kept before the oldest is erased.-->
<maxSizeRollBackups value="10"/>
<maximumFileSize value="500KB"/>
<!--true if always should be logged to the same file, otherwise false.-->
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date|%-5level|%logger|%message%newline%exception"/>
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default level. -->
<root>
<level value="ALL"/> <!-- default: INFO - extensive: ALL -->
<appender-ref ref="RollingFileAppender"/>
</root>
</log4net>
</configuration>

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetZip.Reduced" version="1.9.1.8" targetFramework="net40" />
<package id="log4net" version="2.0.3" targetFramework="net40" />
<package id="SharpDX" version="2.6.2" targetFramework="net20" />
<package id="SharpDX.DirectInput" version="2.6.2" targetFramework="net40" />
</packages>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.
Loading…
Cancel
Save