Skip to content

Commit

Permalink
Merge pull request #166 from nzbgetcom/fix/unpack-err-messages
Browse files Browse the repository at this point in the history
- added Zip exit codes decoder according to 7-Zip [doc](https://documentation.help/7-Zip/exit_codes.htm);
- added warning text that SevenZipCmd may not be valid, in case of problems with installing extensions;
  • Loading branch information
dnzbk authored Feb 13, 2024
2 parents c116a63 + 18b69f8 commit d11ed84
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
14 changes: 7 additions & 7 deletions daemon/extension/ExtensionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ namespace ExtensionManager
};
unpacker.SetArgs(std::move(args));

int res = unpacker.Execute();
int ec = unpacker.Execute();

if (res != 0)
if (ec < 0)
{
if (!FileSystem::DeleteFile(filename.c_str()))
{
return "Failed to unpack and delete temp file: " + filename;
}
return "Failed to unpack " + filename + ". Make sure that the path to 7-Zip is valid.";
}

return "Failed to unpack " + filename;
if (ec > 0)
{
return "Failed to unpack " + filename + ". " + UnpackController::DecodeSevenZipExitCode(ec);
}

if (!FileSystem::DeleteFile(filename.c_str()))
Expand Down
30 changes: 30 additions & 0 deletions daemon/postprocess/Unpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,3 +961,33 @@ bool UnpackController::HasCompletedArchiveFiles(NzbInfo* nzbInfo)

return false;
}

const char* UnpackController::DecodeSevenZipExitCode(int ec)
{
// 7-Zip exit codes according to https://documentation.help/7-Zip/exit_codes.htm
switch (ec)
{
case SevenZipExitCodes::NoError:
return "No error";

case SevenZipExitCodes::Warning:
return "Warning (Non fatal error(s)). \
For example, one or more files were locked by some other application, \
so they were not compressed.";

case SevenZipExitCodes::FatalError:
return "Fatal error";

case SevenZipExitCodes::CmdLineError:
return "Command line error";

case SevenZipExitCodes::NotEnoughMemoryError:
return "Not enough memory for operation";

case SevenZipExitCodes::CanceledByUser:
return "User stopped the process";

default:
return "Unknown 7-Zip error";
};
}
11 changes: 11 additions & 0 deletions daemon/postprocess/Unpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class UnpackController : public Thread, public ScriptController
virtual void Stop();
static void StartJob(PostInfo* postInfo);
static bool HasCompletedArchiveFiles(NzbInfo* nzbInfo);
static const char* DecodeSevenZipExitCode(int ec);

protected:
virtual bool ReadLine(char* buf, int bufSize, FILE* stream);
Expand All @@ -45,6 +46,16 @@ class UnpackController : public Thread, public ScriptController
upSevenZip
};

enum SevenZipExitCodes
{
NoError = 0,
Warning = 1,
FatalError = 2,
CmdLineError = 7,
NotEnoughMemoryError = 8,
CanceledByUser = 255,
};

typedef std::vector<CString> FileListBase;
class FileList : public FileListBase
{
Expand Down
2 changes: 1 addition & 1 deletion webui/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3354,7 +3354,7 @@ var ExtensionManager = (new function($)
{
hideLoadingBanner();
render(getAllExtensions());
showErrorBanner("Failed to download extensions", error);
showErrorBanner("Failed to fetch the list of available extensions", error);
}
);
}
Expand Down
7 changes: 7 additions & 0 deletions webui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,13 @@ <h4 class="alert-heading" id="ExtensionsErrorAlert-title"></h4>
<a href="https://github.com/nzbgetcom/nzbget-extensions/blob/main/extensions.json" target="_blank"> list</a>,
it will be removed without the possibility of reinstalling it.
</span>
<br>
<br>
<span class="label label-warning">NOTE:</span>
<span class="help-option-title">Extension Manager requires 7-Zip to unpack downloaded extensions.
If you are having issues with Extension Manager downloads - please check
<a href="#" onclick="Config.scrollToOption(event, this)">SevenZipCmd</a>.
</span>
</p>

<br>
Expand Down

0 comments on commit d11ed84

Please sign in to comment.