Fixed including the machineId in reports

This commit is contained in:
Kenneth Skovhede
2024-04-18 14:07:05 +02:00
parent 23065d44ef
commit 62f707be6d
2 changed files with 24 additions and 21 deletions
@@ -132,6 +132,9 @@
<Project>{D63E53E4-A458-4C2F-914D-92F715F58ACF}</Project>
<Name>Duplicati.Library.Common</Name>
</ProjectReference>
<ProjectReference Include="..\..\AutoUpdater\Duplicati.Library.AutoUpdater.csproj">
<Name>Duplicati.Library.AutoUpdater</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
@@ -40,8 +40,8 @@ namespace Duplicati.Library.Modules.Builtin
/// </summary>
private static readonly string LOGTAG = Logging.Log.LogTagFromType<ReportHelper>();
/// <summary>
/// The salt used for calculating a backup Id from the remote URL
/// <summary>
/// The salt used for calculating a backup Id from the remote URL
/// </summary>
private const string SALT = "DUPL";
@@ -313,21 +313,21 @@ namespace Duplicati.Library.Modules.Builtin
if (input.IndexOf("%LOCALPATH%", StringComparison.OrdinalIgnoreCase) >= 0 && m_localpath != null)
extra["LocalPath"] = string.Join(System.IO.Path.PathSeparator.ToString(), m_localpath);
if (input.IndexOf("%PARSEDRESULT%", StringComparison.OrdinalIgnoreCase) >= 0)
extra["ParsedResult"] = m_parsedresultlevel;
// If the options contains the key, it is captured by the loop over m_options
// so we only patch it in case it is missing
if (input.IndexOf("%machine-id%", StringComparison.OrdinalIgnoreCase) >= 0)
{
if (!m_options.ContainsKey("machine-id"))
extra["machine-id"] = "";
extra["ParsedResult"] = m_parsedresultlevel;
// If the options contains the key, it is captured by the loop over m_options
// so we only patch it in case it is missing
if (input.IndexOf("%machine-id%", StringComparison.OrdinalIgnoreCase) >= 0)
{
if (!m_options.ContainsKey("machine-id"))
extra["machine-id"] = Library.AutoUpdater.UpdaterManager.InstallID;
}
if (input.IndexOf("%backup-id%", StringComparison.OrdinalIgnoreCase) >= 0)
{
if (!m_options.ContainsKey("backup-id"))
extra["backup-id"] = Library.Utility.Utility.ByteArrayAsHexString(Library.Utility.Utility.RepeatedHashWithSalt(m_remoteurl, SALT));
if (input.IndexOf("%backup-id%", StringComparison.OrdinalIgnoreCase) >= 0)
{
if (!m_options.ContainsKey("backup-id"))
extra["backup-id"] = Library.Utility.Utility.ByteArrayAsHexString(Library.Utility.Utility.RepeatedHashWithSalt(m_remoteurl, SALT));
}
if (input.IndexOf("%backup-name%", StringComparison.OrdinalIgnoreCase) >= 0)
@@ -363,13 +363,13 @@ namespace Duplicati.Library.Modules.Builtin
input = Regex.Replace(input, "\\%" + kv.Key + "\\%", kv.Value ?? "", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
if (!m_options.ContainsKey("backup-name"))
input = Regex.Replace(input, "\\%backup-name\\%", System.IO.Path.GetFileNameWithoutExtension(Duplicati.Library.Utility.Utility.getEntryAssembly().Location) ?? "", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
if (!m_options.ContainsKey("backup-id"))
input = Regex.Replace(input, "\\%backup-id\\%", Library.Utility.Utility.ByteArrayAsHexString(Library.Utility.Utility.RepeatedHashWithSalt(m_remoteurl, SALT)), RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
input = Regex.Replace(input, "\\%backup-name\\%", System.IO.Path.GetFileNameWithoutExtension(Duplicati.Library.Utility.Utility.getEntryAssembly().Location) ?? "", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
if (!m_options.ContainsKey("backup-id"))
input = Regex.Replace(input, "\\%backup-id\\%", Library.Utility.Utility.ByteArrayAsHexString(Library.Utility.Utility.RepeatedHashWithSalt(m_remoteurl, SALT)), RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
if (!m_options.ContainsKey("machine-id"))
input = Regex.Replace(input, "\\%machine-id\\%", "", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
input = Regex.Replace(input, "\\%machine-id\\%", Library.AutoUpdater.UpdaterManager.InstallID, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
input = Regex.Replace(input, "\\%[^\\%]+\\%", "");
return input;