2014-06-27 23:42:48 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2014-07-05 20:46:58 +00:00
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
|
2014-06-27 23:42:48 +00:00
|
|
|
|
|
2014-06-28 20:31:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a list of files found that match 'defaultProfile*.xml'
|
2015-12-22 00:47:23 +00:00
|
|
|
|
/// 20151220BM: return only the single defaultProfile name
|
2014-06-28 20:31:31 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>A list of filenames - can be empty</returns>
|
2015-12-22 00:47:23 +00:00
|
|
|
|
static public String DefaultProfileName
|
2014-06-28 20:31:31 +00:00
|
|
|
|
{
|
2015-12-22 00:47:23 +00:00
|
|
|
|
get { return "defaultProfile.xml"; }
|
2014-06-28 20:31:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the sought default profile as string from GameData.pak
|
|
|
|
|
/// </summary>
|
2016-01-02 00:15:58 +00:00
|
|
|
|
/// <param name="defaultProfileName">The filename of the profile to be extracted </param>
|
2014-06-28 20:31:31 +00:00
|
|
|
|
/// <returns>A string containing the file contents</returns>
|
|
|
|
|
static public String DefaultProfile( String defaultProfileName )
|
2014-06-27 23:42:48 +00:00
|
|
|
|
{
|
2014-07-05 20:46:58 +00:00
|
|
|
|
log.Debug( "DefaultProfile - Entry" );
|
|
|
|
|
|
2014-06-28 13:08:26 +00:00
|
|
|
|
String retVal = "";
|
2014-06-27 23:42:48 +00:00
|
|
|
|
|
2014-07-05 20:46:58 +00:00
|
|
|
|
// first choice a defaultProfile.xml in the app dir distributed with the application ??? to be deleted ???
|
2016-01-02 00:15:58 +00:00
|
|
|
|
if ( File.Exists( SCPath.DefaultProfileName ) ) {
|
|
|
|
|
using ( StreamReader sr = new StreamReader( SCPath.DefaultProfileName ) ) {
|
2014-07-05 20:46:58 +00:00
|
|
|
|
retVal = sr.ReadToEnd( );
|
|
|
|
|
log.Info( "- Use AppDirectory defaultProfile" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// second try to get the SC defaultProfile from the GameData.pak
|
|
|
|
|
retVal = ExtractDefaultProfile( defaultProfileName );
|
2015-12-22 00:47:23 +00:00
|
|
|
|
if ( !String.IsNullOrEmpty( retVal ) ) {
|
2014-07-05 20:46:58 +00:00
|
|
|
|
log.Info( "- Use GamePack defaultProfile" );
|
2014-06-28 13:08:26 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2014-07-05 20:46:58 +00:00
|
|
|
|
// last resort is the built in one
|
2014-06-28 13:08:26 +00:00
|
|
|
|
retVal = SCJMapper_V2.Properties.Resources.defaultProfile;
|
2014-07-05 20:46:58 +00:00
|
|
|
|
log.Info( "- Use built in defaultProfile" );
|
2014-06-27 23:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-28 13:08:26 +00:00
|
|
|
|
return retVal;
|
2014-06-27 23:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-05 20:46:58 +00:00
|
|
|
|
|
2014-06-27 23:42:48 +00:00
|
|
|
|
/// <summary>
|
2014-06-28 20:31:31 +00:00
|
|
|
|
/// Zip Extracts the file to a string
|
2014-06-27 23:42:48 +00:00
|
|
|
|
/// </summary>
|
2014-06-28 20:31:31 +00:00
|
|
|
|
static private String ExtractDefaultProfile( String defaultProfileName )
|
2014-06-27 23:42:48 +00:00
|
|
|
|
{
|
2014-07-05 20:46:58 +00:00
|
|
|
|
log.Debug( "ExtractDefaultProfile - Entry" );
|
|
|
|
|
|
2014-06-28 13:08:26 +00:00
|
|
|
|
String retVal = "";
|
|
|
|
|
if ( File.Exists( SCPath.SCGameData_pak ) ) {
|
|
|
|
|
using ( ZipFile zip = ZipFile.Read( SCPath.SCGameData_pak ) ) {
|
|
|
|
|
zip.CaseSensitiveRetrieval = false;
|
2014-07-05 20:46:58 +00:00
|
|
|
|
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
|
|
|
|
|
}
|
2014-06-28 13:08:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-05 20:46:58 +00:00
|
|
|
|
catch ( Exception ex ) {
|
|
|
|
|
log.Error( "Unexpected", ex );
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-28 13:08:26 +00:00
|
|
|
|
}
|
2014-06-27 23:42:48 +00:00
|
|
|
|
}
|
2014-06-28 13:08:26 +00:00
|
|
|
|
return retVal;
|
2014-06-27 23:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|