Skip to content

Commit e760c27

Browse files
author
Hamish
committed
Merge branch 'develop'
2 parents 3eae751 + b1749b9 commit e760c27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1279
-549
lines changed

src/kOSMinimiser/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>

src/kOSMinimiser/Program.cs

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using System.Text.RegularExpressions;
3+
4+
namespace kOSMinimiser
5+
{
6+
class Program
7+
{
8+
static string filename;
9+
10+
static void Main(string[] args)
11+
{
12+
try
13+
{
14+
filename = args[0];
15+
}
16+
catch
17+
{
18+
Console.WriteLine("Sorry, There seems to be a problem with your syntax. You need to run kOSminimiser.exe filename.ks");
19+
Console.WriteLine("Press enter to close...");
20+
Console.ReadLine();
21+
Environment.Exit(0);
22+
}
23+
24+
Minimiser.Minimise(filename);
25+
}
26+
}
27+
28+
class Minimiser
29+
{
30+
static public void Minimise(string filename)
31+
{
32+
//Open file into string s
33+
string s = Open(filename);
34+
int initial = s.Length * sizeof(Char);
35+
36+
//Remove comments
37+
s = Regex.Replace(s, @"//(.*?)\r?\n", me => {
38+
if (me.Value.StartsWith("//"))
39+
return me.Value.StartsWith("//") ? Environment.NewLine : "";
40+
return me.Value;
41+
}, RegexOptions.Singleline);
42+
43+
//Remove double spaces
44+
s = s.Replace(" ", " ");
45+
46+
//Remove lines containing only whitespace
47+
s = Regex.Replace(s, @"^\s+$[\r\n]*", "", RegexOptions.Multiline);
48+
49+
int final = s.Length * sizeof(Char);
50+
51+
Save(filename, s);
52+
Console.WriteLine("Initial size: " + initial.ToString() + " bytes\r\nFinal size: " + final.ToString() + " bytes\r\nSaved: " + (initial - final).ToString() +" bytes");
53+
Console.WriteLine("Press enter to close...");
54+
Console.ReadLine();
55+
}
56+
57+
static string Open(string filename)
58+
{
59+
try {
60+
string s;
61+
System.IO.StreamReader objReader;
62+
objReader = new System.IO.StreamReader(filename);
63+
s = objReader.ReadToEnd();
64+
objReader.Close();
65+
return s;
66+
}catch
67+
{
68+
Console.WriteLine("There was a problem opening the script. Press enter to continue");
69+
Console.ReadLine();
70+
Environment.Exit(0);
71+
return null;
72+
}
73+
}
74+
75+
static void Save(string filename, string buffer)
76+
{
77+
filename = filename.Remove(filename.Length - 3);
78+
filename = filename + "-minimised.ks";
79+
System.IO.File.WriteAllText(filename, buffer);
80+
}
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("kOSMinimiser")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("kOSMinimiser")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("4b417e9b-11d8-46b5-9d47-f36d4008b128")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

src/kOSMinimiser/kOSMinimiser.csproj

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{4B417E9B-11D8-46B5-9D47-F36D4008B128}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>kOSMinimiser</RootNamespace>
11+
<AssemblyName>kOSMinimiser</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Net.Http" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="Program.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
</ItemGroup>
49+
<ItemGroup>
50+
<None Include="App.config" />
51+
</ItemGroup>
52+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
53+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
54+
Other similar extension points exist, see Microsoft.Common.targets.
55+
<Target Name="BeforeBuild">
56+
</Target>
57+
<Target Name="AfterBuild">
58+
</Target>
59+
-->
60+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
4+
<StartArguments>example.ks</StartArguments>
5+
</PropertyGroup>
6+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
7+
<StartArguments>example.ks</StartArguments>
8+
</PropertyGroup>
9+
</Project>

src/koside.sln

+17-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "koside", "koside\koside.csp
77
EndProject
88
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "Installer", "Installer\Installer.wixproj", "{B014AAA1-4EEF-48CE-8ECB-FDFF40A0127D}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScriptMinimiser", "ScriptMinimiser\ScriptMinimiser.csproj", "{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}"
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "kOSMinimiser", "kOSMinimiser\kOSMinimiser.csproj", "{4B417E9B-11D8-46B5-9D47-F36D4008B128}"
1111
EndProject
1212
Global
1313
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -47,22 +47,22 @@ Global
4747
{B014AAA1-4EEF-48CE-8ECB-FDFF40A0127D}.Release|x64.ActiveCfg = Release|x86
4848
{B014AAA1-4EEF-48CE-8ECB-FDFF40A0127D}.Release|x86.ActiveCfg = Release|x86
4949
{B014AAA1-4EEF-48CE-8ECB-FDFF40A0127D}.Release|x86.Build.0 = Release|x86
50-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Debug|Any CPU.Build.0 = Debug|Any CPU
52-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Debug|ARM.ActiveCfg = Debug|Any CPU
53-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Debug|ARM.Build.0 = Debug|Any CPU
54-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Debug|x64.ActiveCfg = Debug|Any CPU
55-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Debug|x64.Build.0 = Debug|Any CPU
56-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Debug|x86.ActiveCfg = Debug|Any CPU
57-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Debug|x86.Build.0 = Debug|Any CPU
58-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Release|Any CPU.ActiveCfg = Release|Any CPU
59-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Release|Any CPU.Build.0 = Release|Any CPU
60-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Release|ARM.ActiveCfg = Release|Any CPU
61-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Release|ARM.Build.0 = Release|Any CPU
62-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Release|x64.ActiveCfg = Release|Any CPU
63-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Release|x64.Build.0 = Release|Any CPU
64-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Release|x86.ActiveCfg = Release|Any CPU
65-
{BE5E16FB-D48D-4FC3-A031-E18ADFC2B85C}.Release|x86.Build.0 = Release|Any CPU
50+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Debug|ARM.ActiveCfg = Debug|Any CPU
53+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Debug|ARM.Build.0 = Debug|Any CPU
54+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Debug|x64.ActiveCfg = Debug|Any CPU
55+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Debug|x64.Build.0 = Debug|Any CPU
56+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Debug|x86.ActiveCfg = Debug|Any CPU
57+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Debug|x86.Build.0 = Debug|Any CPU
58+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Release|Any CPU.ActiveCfg = Release|Any CPU
59+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Release|Any CPU.Build.0 = Release|Any CPU
60+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Release|ARM.ActiveCfg = Release|Any CPU
61+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Release|ARM.Build.0 = Release|Any CPU
62+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Release|x64.ActiveCfg = Release|Any CPU
63+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Release|x64.Build.0 = Release|Any CPU
64+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Release|x86.ActiveCfg = Release|Any CPU
65+
{4B417E9B-11D8-46B5-9D47-F36D4008B128}.Release|x86.Build.0 = Release|Any CPU
6666
EndGlobalSection
6767
GlobalSection(SolutionProperties) = preSolution
6868
HideSolutionNode = FALSE

src/koside/App.config

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
</startup>
1111
<userSettings>
1212
<koside.Properties.Settings>
13-
<setting name="KSPLoc" serializeAs="String">
14-
<value />
15-
</setting>
1613
<setting name="DarkMode" serializeAs="String">
1714
<value>False</value>
1815
</setting>
@@ -22,6 +19,9 @@
2219
<setting name="OS" serializeAs="String">
2320
<value />
2421
</setting>
22+
<setting name="Uppercase" serializeAs="String">
23+
<value>True</value>
24+
</setting>
2525
</koside.Properties.Settings>
2626
</userSettings>
2727
</configuration>

src/koside/Classes/FirstRun.cs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.Windows.Forms;
2+
3+
namespace koside
4+
{
5+
class FirstRun
6+
{
7+
static public void Entry()
8+
{
9+
Properties.Settings.Default.FirstRun = false;
10+
Properties.Settings.Default.OS = "Windows";
11+
Properties.Settings.Default.KSPLoc = new System.Collections.Generic.List<string>();
12+
13+
string ksp = KSPPathTools.KSPDirectory(Steam());
14+
15+
if (ksp == null)
16+
ShowSetup();
17+
else
18+
{
19+
if (MessageBox.Show("We have found KSP at: " + ksp + "\r\nIs this correct?", "Steam KSP found", MessageBoxButtons.YesNo) == DialogResult.Yes)
20+
{
21+
Properties.Settings.Default.KSPLoc.Add(ksp);
22+
if (MessageBox.Show("Would you like to add additional install locations? (Can be done in settings later)", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
23+
ShowSetup();
24+
}else if (MessageBox.Show("Would you like to add the correct install now? (Can be done in settings later)", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
25+
ShowSetup();
26+
}
27+
}
28+
29+
static private string Steam()
30+
{
31+
bool linux = KSPPathTools.IsLinux();
32+
string steam;
33+
34+
if (linux == true)
35+
{
36+
Properties.Settings.Default.OS = "Linux";
37+
return steam = KSPPathTools.LinuxSteam();
38+
}
39+
else
40+
return steam = KSPPathTools.WindowsSteam();
41+
}
42+
43+
static void ShowSetup()
44+
{
45+
Forms.Setup setup = new Forms.Setup();
46+
setup.ShowDialog();
47+
}
48+
}
49+
}

src/koside/Classes/KSPPathTools.cs

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Linq;
3+
using Microsoft.Win32;
4+
using System.IO;
5+
6+
namespace koside
7+
{
8+
class KSPPathTools
9+
{
10+
static public bool IsLinux()
11+
{
12+
var drives = DriveInfo.GetDrives();
13+
if (drives.Where(data => data.Name == "Z:\\").Count() == 1)
14+
{
15+
RegistryKey OurKey = Registry.CurrentUser;
16+
OurKey = OurKey.OpenSubKey(@"SOFTWARE\", false);
17+
RegistryKey key = OurKey.OpenSubKey("Wine");
18+
if (key != null)
19+
return true;
20+
else
21+
return false;
22+
}
23+
else
24+
return false;
25+
}
26+
27+
static public string WindowsSteam()
28+
{
29+
string steam = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Valve\Steam", @"SteamPath", null);
30+
31+
if (steam != null && Directory.Exists(steam))
32+
return NormalizeWindowsPath(steam);
33+
else
34+
return null;
35+
}
36+
37+
static public string LinuxSteam()
38+
{
39+
if (Directory.Exists("steam"))
40+
return "steam";
41+
else
42+
return null;
43+
}
44+
45+
public static string KSPDirectory(string steam)
46+
{
47+
string ksp_path;
48+
if (steam == null)
49+
return null;
50+
51+
ksp_path = Path.Combine(steam, "SteamApps", "common", "Kerbal Space Program");
52+
if (Directory.Exists(ksp_path))
53+
return ksp_path;
54+
55+
ksp_path = Path.Combine(steam, "steamapps", "common", "Kerbal Space Program");
56+
if (Directory.Exists(ksp_path))
57+
return ksp_path;
58+
59+
return null;
60+
61+
}
62+
63+
private static string NormalizePath(string path)
64+
{
65+
return path.Replace('\\', '/').TrimEnd('/');
66+
}
67+
68+
private static string NormalizeWindowsPath(string path)
69+
{
70+
return path.Replace('/', '\\');
71+
}
72+
73+
}
74+
}

0 commit comments

Comments
 (0)