Skip to content

Commit

Permalink
Even less throw, even more result.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed Mar 8, 2024
1 parent 74b1a9f commit 2934a8d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,19 +358,28 @@ string password
}
catch (WebException wex)
{
Log.Warn("Unable to create a WebRequest for the specified file (WebException): " + wex.Message);
throw new InvalidOperationException();
return CreateEntityResult<HttpWebRequest>.FromError
(
"Unable to create a WebRequest for the specified file.",
wex
);
}
catch (ArgumentException aex)
{
Log.Warn("Unable to create a WebRequest for the specified file (ArgumentException): " + aex.Message);
throw new InvalidOperationException();
return CreateEntityResult<HttpWebRequest>.FromError
(
"Unable to create a WebRequest for the specified file.",
aex
);
}
catch (UriFormatException uex)
{
Log.Warn("Unable to create a WebRequest for the specified file (UriFormatException): " + uex.Message + "\n" +
"You may need to add \"http://\" before the url in the config.");
throw new InvalidOperationException();
return CreateEntityResult<HttpWebRequest>.FromError
(
"Unable to create a WebRequest for the specified file. You may need to add \"http://\" before " +
"the url in the config.",
uex
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,7 @@ public override async Task<RetrieveEntityResult<bool>> IsModuleOutdatedAsync(EMo
}
default:
{
throw new ArgumentOutOfRangeException
(
nameof(module),
module,
"An invalid module value was passed to IsModuleOutdated."
);
throw new ArgumentOutOfRangeException();
}
}

Expand Down Expand Up @@ -495,12 +490,7 @@ protected virtual async Task<DetermineConditionResult> DownloadManifestEntryAsyn
}
default:
{
throw new ArgumentOutOfRangeException
(
nameof(module),
module,
"An invalid module value was passed to DownloadManifestEntry."
);
throw new ArgumentOutOfRangeException();
}
}

Expand Down Expand Up @@ -610,25 +600,7 @@ protected virtual async Task<DetermineConditionResult> DownloadManifestEntryAsyn
/// </exception>
protected virtual async Task<RetrieveEntityResult<bool>> IsModuleManifestOutdatedAsync(EModule module)
{
string manifestPath;
switch (module)
{
case EModule.Launcher:
case EModule.Game:
{
manifestPath = _fileManifestHandler.GetManifestPath((EManifestType)module, false);
break;
}
default:
{
throw new ArgumentOutOfRangeException
(
nameof(module),
module,
"An invalid module value was passed to RefreshModuleManifest."
);
}
}
var manifestPath = _fileManifestHandler.GetManifestPath((EManifestType)module, false);

if (!File.Exists(manifestPath))
{
Expand Down Expand Up @@ -659,36 +631,18 @@ protected virtual async Task<RetrieveEntityResult<bool>> IsModuleManifestOutdate
/// </exception>
protected virtual async Task<RetrieveEntityResult<string>> GetRemoteModuleManifestChecksumAsync(EModule module)
{
string checksum;
switch (module)
{
case EModule.Launcher:
case EModule.Game:
{
var getRemoteChecksum = await ReadRemoteFileAsync
(
_fileManifestHandler.GetManifestChecksumURL((EManifestType)module)
);

if (!getRemoteChecksum.IsSuccess)
{
return RetrieveEntityResult<string>.FromError(getRemoteChecksum);
}
var getRemoteChecksum = await ReadRemoteFileAsync
(
_fileManifestHandler.GetManifestChecksumURL((EManifestType)module)
);

checksum = getRemoteChecksum.Entity.RemoveLineSeparatorsAndNulls();
break;
}
default:
{
throw new ArgumentOutOfRangeException
(
nameof(module),
module,
"An invalid module value was passed to GetRemoteModuleManifestChecksum."
);
}
if (!getRemoteChecksum.IsSuccess)
{
return RetrieveEntityResult<string>.FromError(getRemoteChecksum);
}

var checksum = getRemoteChecksum.Entity.RemoveLineSeparatorsAndNulls();

return checksum.RemoveLineSeparatorsAndNulls();
}

Expand All @@ -702,26 +656,7 @@ protected virtual async Task<RetrieveEntityResult<string>> GetRemoteModuleManife
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
protected virtual async Task<DetermineConditionResult> RefreshModuleManifestAsync(EModule module)
{
bool manifestExists;
switch (module)
{
case EModule.Launcher:
case EModule.Game:
{
manifestExists = File.Exists(_fileManifestHandler.GetManifestPath((EManifestType)module, false));
break;
}
default:
{
throw new ArgumentOutOfRangeException
(
nameof(module),
module,
"An invalid module value was passed to RefreshModuleManifest"
);
}
}

var manifestExists = File.Exists(_fileManifestHandler.GetManifestPath((EManifestType)module, false));
if (manifestExists)
{
var getIsOutdated = await IsModuleManifestOutdatedAsync(module);
Expand Down Expand Up @@ -763,31 +698,9 @@ protected virtual async Task<DetermineConditionResult> RefreshModuleManifestAsyn
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
protected virtual async Task<DetermineConditionResult> DownloadModuleManifestAsync(EModule module)
{
string remoteURL;
string localPath;
string oldLocalPath;

switch (module)
{
case EModule.Launcher:
case EModule.Game:
{
remoteURL = _fileManifestHandler.GetManifestURL((EManifestType)module);
localPath = _fileManifestHandler.GetManifestPath((EManifestType)module, false);
oldLocalPath = _fileManifestHandler.GetManifestPath((EManifestType)module, true);

break;
}
default:
{
throw new ArgumentOutOfRangeException
(
nameof(module),
module,
"An invalid module value was passed to DownloadModuleManifest"
);
}
}
var remoteURL = _fileManifestHandler.GetManifestURL((EManifestType)module);
var localPath = _fileManifestHandler.GetManifestPath((EManifestType)module, false);
var oldLocalPath = _fileManifestHandler.GetManifestPath((EManifestType)module, true);

try
{
Expand Down

0 comments on commit 2934a8d

Please sign in to comment.