Skip to content

Commit

Permalink
Merge #2776 Suppress autostart warning
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Jun 10, 2019
2 parents f574d14 + 4fcd298 commit 2afc45b
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 27 deletions.
24 changes: 9 additions & 15 deletions Core/KSPManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ public class KSPManager : IDisposable

public string AutoStartInstance
{
get { return Win32Registry.AutoStartInstance; }
get
{
return HasInstance(Win32Registry.AutoStartInstance)
? Win32Registry.AutoStartInstance
: null;
}
private set
{
if (!String.IsNullOrEmpty(value) && !HasInstance(value))
Expand Down Expand Up @@ -94,7 +99,6 @@ internal KSP _GetPreferredInstance()
// We check both null and "" as we can't write NULL to the registry, so we write an empty string instead
// This is necessary so we can indicate that the user wants to reset the current AutoStartInstance without clearing the windows registry keys!
if (!string.IsNullOrEmpty(AutoStartInstance)
&& HasInstance(AutoStartInstance)
&& instances[AutoStartInstance].Valid)
{
return instances[AutoStartInstance];
Expand Down Expand Up @@ -143,7 +147,7 @@ public KSP AddInstance(KSP ksp_instance)
{
string name = ksp_instance.Name;
instances.Add(name, ksp_instance);
Win32Registry.SetRegistryToInstances(instances, AutoStartInstance);
Win32Registry.SetRegistryToInstances(instances);
}
else
{
Expand Down Expand Up @@ -313,7 +317,7 @@ private bool InstanceNameIsValid(string name)
public void RemoveInstance(string name)
{
instances.Remove(name);
Win32Registry.SetRegistryToInstances(instances, AutoStartInstance);
Win32Registry.SetRegistryToInstances(instances);
}

/// <summary>
Expand All @@ -326,7 +330,7 @@ public void RenameInstance(string from, string to)
instances.Remove(from);
ksp.Name = to;
instances.Add(to, ksp);
Win32Registry.SetRegistryToInstances(instances, AutoStartInstance);
Win32Registry.SetRegistryToInstances(instances);
}

/// <summary>
Expand Down Expand Up @@ -418,16 +422,6 @@ public void LoadInstancesFromRegistry()
}
string failReason;
TrySetupCache(Win32Registry.DownloadCacheDir, out failReason);

try
{
AutoStartInstance = Win32Registry.AutoStartInstance;
}
catch (InvalidKSPInstanceKraken e)
{
log.WarnFormat("Auto-start instance was invalid: {0}", e.Message);
AutoStartInstance = null;
}
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ private void SealionTransaction()
}
else if (enlisted_tx != current_tx)
{
log.Error("CKAN registry does not support nested transactions.");
throw new TransactionalKraken("CKAN registry does not support nested transactions.");
}

Expand Down
1 change: 0 additions & 1 deletion Core/Types/CkanModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@ public CkanModule(string json, IGameComparator comparator)

string error = String.Format("{0} missing required field {1}", identifier, field);

log.Error(error);
throw new BadMetadataKraken(null, error);
}
}
Expand Down
5 changes: 2 additions & 3 deletions Core/Win32Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace CKAN
public interface IWin32Registry
{
string AutoStartInstance { get; set; }
void SetRegistryToInstances(SortedList<string, KSP> instances, string autoStartInstance);
void SetRegistryToInstances(SortedList<string, KSP> instances);
IEnumerable<Tuple<string, string>> GetInstances();
string GetKSPBuilds();
void SetKSPBuilds(string buildMap);
Expand Down Expand Up @@ -121,9 +121,8 @@ private Tuple<string, string> GetInstance(int i)
GetRegistryValue("KSPInstancePath_" + i, string.Empty));
}

public void SetRegistryToInstances(SortedList<string, KSP> instances, string autoStartInstance)
public void SetRegistryToInstances(SortedList<string, KSP> instances)
{
SetAutoStartInstance(autoStartInstance ?? string.Empty);
SetNumberOfInstances(instances.Count);

foreach (var instance in instances.Select((instance,i)=>
Expand Down
1 change: 0 additions & 1 deletion Netkan/Transformers/EpochTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public IEnumerable<Metadata> Transform(Metadata metadata)
}
else
{
Log.Error("Invalid epoch: " + epoch);
throw new BadMetadataKraken(null, "Invalid epoch: " + epoch + "In " + json["identifier"]);
}
}
Expand Down
3 changes: 1 addition & 2 deletions Tests/Core/FakeWin32Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ public Tuple<string, string> GetInstance(int i)
/// <returns>
/// Returns
/// </returns>
public void SetRegistryToInstances(SortedList<string, CKAN.KSP> instances, string autoStartInstance)
public void SetRegistryToInstances(SortedList<string, CKAN.KSP> instances)
{
Instances =
instances.Select(kvpair => new Tuple<string, string>(kvpair.Key, kvpair.Value.GameDir())).ToList();
AutoStartInstance = autoStartInstance;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Tests/Core/KSPManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public void HasInstance_ReturnsTrueIfInstanceByThatName()
}

[Test]
public void SetAutoStart_VaildName_SetsAutoStart()
public void SetAutoStart_ValidName_SetsAutoStart()
{
Assert.That(manager.AutoStartInstance, Is.EqualTo(string.Empty));
Assert.That(manager.AutoStartInstance, Is.EqualTo(null));

manager.SetAutoStart(nameInReg);
Assert.That(manager.AutoStartInstance, Is.EqualTo(nameInReg));
Expand Down
2 changes: 1 addition & 1 deletion Tests/Core/Net/Net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private static void BadDownload()

[Test]
[Category("Online")]
public void DownloadThrowsOnInvaildURL()
public void DownloadThrowsOnInvalidURL()
{
// Download should throw an exception on an invalid URL.
Assert.That(BadDownload, Throws.Exception);
Expand Down
4 changes: 3 additions & 1 deletion Tests/NetKAN/MainClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ public void ApplyEpochNumber(string json, string orig_version, string new_versio
}

[TestCase(@"{""spec_version"": 1, ""version"" : ""1.01""}", false)]
[TestCase(@"{""spec_version"": 1, ""version"" : ""1.01"", ""x_netkan_epoch"" : ""1""}", false)]
[TestCase(@"{""spec_version"": 1, ""version"" : ""1.01"", ""x_netkan_epoch"" : ""3""}", false)]
[TestCase(@"{""spec_version"": 1, ""version"" : ""1.01"", ""x_netkan_epoch"" : ""a""}", true)]
[TestCase(@"{""spec_version"": 1, ""version"" : ""1.01"", ""x_netkan_epoch"" : ""-1""}", true)]
[TestCase(@"{""spec_version"": 1, ""version"" : ""1.01"", ""x_netkan_epoch"" : ""5.5""}", true)]
public void Invaild(string json, bool expected_to_throw)
public void Invalid(string json, bool expected_to_throw)
{
TestDelegate test_delegate = () => new EpochTransformer().Transform(new Metadata(JObject.Parse(json))).First().Json();
if (expected_to_throw)
Expand Down

0 comments on commit 2afc45b

Please sign in to comment.