@@ -76,6 +76,7 @@
<DependentUpon>KerbalPreviewWindow.cs</DependentUpon>
</Compile>
<Compile Include="Kerbals\RosterParser.cs" />
<Compile Include="Logging\Logger.cs" />
<Compile Include="NameGenerator\NameGenerator.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KerbalGenerator.Logging{
public class Logger {

private static readonly string logPath = Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "BadWater"),"KerbalGen"), "Logs");
private static readonly string logFile = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "BadWater"),"KerbalGen"), "Logs"), "log.txt");
private static List<string> log = new List<string>();



public static void LogEvent( string str ) {
ValidateDirectory( );
ReadLog( );
string logMessage = FormatErrorSeperator("Event: " + DateTime.Now.ToString());
logMessage += Environment.NewLine + str;
log.Add( logMessage );
WriteLog( );
}

internal static void LogNewLine( string s ) {
log.Add( "-" + s );
WriteLog( );
}

public static void LogError( Exception ex, object Sender ) {
ValidateDirectory( );
ReadLog( );
Exception newException = ex;
string logMessage = FormatErrorSeperator( "Error! " + DateTime.Now.ToString( ) );
logMessage += Environment.NewLine;
logMessage += Sender.ToString( );
logMessage += Environment.NewLine;
logMessage += ex.ToString( );
log.Add( logMessage );
WriteLog( );
}

private static void ValidateDirectory( ) {
//since were using static Logging methods, check this EVERY time a log thing is thing'd
if ( !Directory.Exists( logPath ) ) {
Directory.CreateDirectory( logPath );
}
else {

}
}
//ReadLog
private static void ReadLog( ) {
if ( File.Exists( logFile ) ) {
log = File.ReadAllLines( logFile ).ToList( );
}
}

private static void WriteLog( ) {
ValidateDirectory( );
File.WriteAllLines( logFile, log );
}

private static string FormatErrorSeperator( string str ) {
int length = str.Length;
string tmpErrorMsg = "";
string seperator = "";
for ( int i = 0; i < length * 2; i++ ) {
seperator += "=";
}
int padder = (seperator.Length) - (length + 1);
//Get the center point of tmp subtract length of str + 1 for the "+" upcoming
str = str.PadLeft( ( padder / 2 + length ) ).PadRight( (length + padder) -1 );

tmpErrorMsg = seperator + Environment.NewLine + "+" + str + "+" + Environment.NewLine + seperator;
return tmpErrorMsg;
}

}
}
@@ -5512,15 +5512,17 @@ public class NameGenerator {
#endregion
#endregion
public static string GenerateName( string name, bool rndName, bool female, bool isKerman ) {
string tmpName = "";
if ( rndName ) {
return GenerateName( female, isKerman );
tmpName = CamelCaseMe( GenerateName( female, isKerman ) );
}
else {
if ( isKerman ) {
name = name + " Kerman";
tmpName = name + " Kerman";
}
return name;
tmpName = CamelCaseMe( tmpName );
}
return tmpName;
}
public static string GenerateName( bool female, bool isKerman ) {
int maxNameLength = 18;
@@ -5545,6 +5547,19 @@ public class NameGenerator {
return name;
}

private static string CamelCaseMe( string name ) {
string result = name;
string[ ] tmpName = name.Split(' ');
for ( int i = 0; i < tmpName.Length; i++ ) {
string s = tmpName[i];
if ( s.Length > 0 ) {
tmpName[i] = s[0].ToString( ).ToUpper( ) + s.Substring( 1 ).ToLower();
}
}
result = string.Join( " ", tmpName );
return result;
}

private static string PickLastName( bool female ) {
float pickFemale = Util.GetRandFloat();
//take a first name;
@@ -4,6 +4,8 @@
using System.Linq;
using System.Windows.Forms;

using KerbalGenerator.Logging;

namespace KerbalGenerator {
static class Program {
/// <summary>
@@ -12,10 +14,11 @@ static class Program {
///
[STAThread]
static void Main( ) {
Logger.LogEvent( "New Run" );
Application.EnableVisualStyles( );
Application.SetCompatibleTextRenderingDefault( false );
Application.Run( new frm_Krb_Gen( ) );

Logger.LogEvent( "Program Exited Gracefully!" );
}
}
}