Skip to content

Commit

Permalink
Merge branch 'master' into improve-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tombogle committed Nov 19, 2024
2 parents c82cea2 + 742fbfe commit 6baf806
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 80 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- BREAKING CHANGE: Replaced dependency on DotNetZip with System.IO.Compression.ZipFile (Client installers will need to be changed.)
- BREAKING CHANGE: Changed to target .Net Framework 4.6.2 instead of 4.6.1
- [SIL.Windows.Forms] Look for PNG data on clipboard before checking for plain image in WindowsClipboard.GetImageFromClipboard() in order to preserve transparency in copied images.
- [SIL.Windows.Forms] Changed layout of SILAboutBox to accommodate wider SIL logo.
Expand Down
2 changes: 2 additions & 0 deletions Palaso.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=FFprobe/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=filenames/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=fran_00E7ais/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=fwbackup/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=fwdata/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=glist/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Glyssen/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Hasso/@EntryIndexedValue">True</s:Boolean>
Expand Down
52 changes: 29 additions & 23 deletions SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.IO.Packaging;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Ionic.Zip;
using NUnit.Framework;
using SIL.Core.ClearShare;
using SIL.IO;
Expand Down Expand Up @@ -120,23 +121,25 @@ public void GetMode_MultipleTypesInList_ReturnsCorrectMetsList()
[Test]
public void GetMode_ZipFileWithMultipleTypesInList_ReturnsCorrectMetsList()
{
ZipFile zipFile = new ZipFile();
zipFile.AddEntry("blah.mp3", "whatever");
zipFile.AddEntry("blah.doc", "whatever");
zipFile.AddEntry("blah.niff", "whatever");
var tempFile = TempFile.WithExtension("zip");
try
{
zipFile.Save(tempFile.Path);
var mode = m_model.GetMode(new[] { zipFile.Name });
Assert.AreEqual("\"" + RampArchivingDlgViewModel.kFileTypeModeList + "\":[\"" +
RobustFile.Delete(tempFile.Path);
using (var zipFile = ZipFile.Open(tempFile.Path, ZipArchiveMode.Create))
{
// For good measure, make sure we can handle filenames with Unicode surrogate pairs
zipFile.CreateEntry("blah\uD800\uDC00\ud803\ude6d\udbff\udfff.mp3");
zipFile.CreateEntry("blah.doc");
zipFile.CreateEntry("blah.niff");
}
var mode = m_model.GetMode(new[] { tempFile.Path });
Assert.That(mode, Is.EqualTo("\"" + RampArchivingDlgViewModel.kFileTypeModeList + "\":[\"" +
RampArchivingDlgViewModel.kModeSpeech + "\",\"" +
RampArchivingDlgViewModel.kModeText + "\",\"" +
RampArchivingDlgViewModel.kModeMusicalNotation + "\"]", mode);
RampArchivingDlgViewModel.kModeMusicalNotation + "\"]"));
}
finally
{
zipFile.Dispose();
tempFile.Dispose();
}
}
Expand All @@ -145,24 +148,25 @@ public void GetMode_ZipFileWithMultipleTypesInList_ReturnsCorrectMetsList()
[Test]
public void GetMode_FwBackupFileWithMultipleTypesInList_ReturnsCorrectMetsList()
{
ZipFile zipFile = new ZipFile();
zipFile.AddEntry("blah.fwdata", "whatever");
zipFile.AddEntry("fonts/blah.ttf", "whatever");
zipFile.AddEntry("images/blah.jpeg", "whatever");
var tempFile = TempFile.WithExtension("fwbackup");
try
{
zipFile.Save(tempFile.Path);
var mode = m_model.GetMode(new[] { zipFile.Name });
Assert.AreEqual("\"" + RampArchivingDlgViewModel.kFileTypeModeList + "\":[\"" +
RobustFile.Delete(tempFile.Path);
using (var zipFile = ZipFile.Open(tempFile.Path, ZipArchiveMode.Create))
{
zipFile.CreateEntry("blah.fwdata");
zipFile.CreateEntry("fonts/blah.ttf");
zipFile.CreateEntry("images/blah.jpeg");
}
var mode = m_model.GetMode(new[] { tempFile.Path });
Assert.That(mode, Is.EqualTo("\"" + RampArchivingDlgViewModel.kFileTypeModeList + "\":[\"" +
RampArchivingDlgViewModel.kModeText + "\",\"" +
RampArchivingDlgViewModel.kModeDataset + "\",\"" +
RampArchivingDlgViewModel.kModeSoftwareOrFont + "\",\"" +
RampArchivingDlgViewModel.kModePhotograph + "\"]", mode);
RampArchivingDlgViewModel.kModePhotograph + "\"]"));
}
finally
{
zipFile.Dispose();
tempFile.Dispose();
}
}
Expand Down Expand Up @@ -407,10 +411,12 @@ public void SetAbstract_Null_ThrowsArgumentNullException()
[Test]
public void SetAbstract_ThreeLanguages_IncludedInMetsData()
{
Dictionary<string, string> abstracts = new Dictionary<string, string>();
abstracts["eng"] = "This is pretty abstract";
abstracts["fra"] = "C'est assez abstrait";
abstracts["spa"] = "Esto es bastante abstracto";
Dictionary<string, string> abstracts = new Dictionary<string, string>
{
["eng"] = "This is pretty abstract",
["fra"] = "C'est assez abstrait",
["spa"] = "Esto es bastante abstracto"
};
m_model.SetAbstract(abstracts);
var data = m_model.GetMetadata();
Assert.AreEqual("{\"dc.title\":\"Test Title\"," +
Expand Down
3 changes: 2 additions & 1 deletion SIL.Archiving.Tests/SIL.Archiving.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="DotNetZip" Version="1.16.0" />
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1" PrivateAssets="all" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.2" PrivateAssets="All" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
53 changes: 23 additions & 30 deletions SIL.Archiving/RampArchivingDlgViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Security;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Ionic.Zip;
using JetBrains.Annotations;
using SIL.Core.ClearShare;
using SIL.Extensions;
Expand Down Expand Up @@ -267,8 +267,8 @@ private void AddModesToSet(IEnumerable<string> files)
{
if (FileUtils.GetIsZipFile(file))
{
using (var zipFile = new ZipFile(file))
AddModesToSet(zipFile.EntryFileNames);
using (var zipArchive = ZipFile.OpenRead(file))
AddModesToSet(zipArchive.Entries.Select(e => e.FullName));
continue;
}

Expand Down Expand Up @@ -1674,41 +1674,34 @@ private void CreateZipFile(CancellationToken cancellationToken)

ReportMajorProgressPoint(StringId.SavingFilesInPackage, cancellationToken);

using (var zip = new ZipFile())
using (var zip = ZipFile.Open(PackagePath, ZipArchiveMode.Create))
{
// RAMP packages must not be compressed or RAMP can't read them.
zip.UseZip64WhenSaving = Zip64Option.AsNecessary; // See SP-2291
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.None;
zip.AddFiles(filesToCopyAndZip.Values, @"\");
zip.AddFile(_metsFilePath, Empty);
zip.SaveProgress += delegate(object sender, SaveProgressEventArgs args)
{
HandleZipSaveProgress(args, cancellationToken);
};
zip.Save(PackagePath);
foreach (var filePath in filesToCopyAndZip.Values)
AddFileToZipArchive(zip, filePath, cancellationToken);

if (!cancellationToken.IsCancellationRequested)
Thread.Sleep(800);
AddFileToZipArchive(zip, _metsFilePath, cancellationToken);
}
}


/// ------------------------------------------------------------------------------------
/// <summary>
/// This is called by the Save method on the ZipFile class as the zip file is being
/// saved to the disk.
/// Add the requested file to the zip archive after reporting progress and checking for
/// cancellation by user.
/// </summary>
/// <remarks>RAMP packages must not be compressed or RAMP can't read them.</remarks>
/// ------------------------------------------------------------------------------------
private void HandleZipSaveProgress(SaveProgressEventArgs e,
private void AddFileToZipArchive(ZipArchive zip, string filePath,
CancellationToken cancellationToken)
{
if (e.EventType != ZipProgressEventType.Saving_BeforeWriteEntry)
return;

if (_progressMessages.TryGetValue(e.CurrentEntry.FileName, out var msg))
if (_progressMessages.TryGetValue(filePath, out var msg))
DisplayMessage(msg, MessageType.Progress);

ReportProgress(Path.GetFileName(e.CurrentEntry.FileName), MessageType.Detail, cancellationToken);
var fileName = Path.GetFileName(filePath);

ReportProgress(fileName, MessageType.Detail, cancellationToken);

zip.CreateEntryFromFile(filePath, fileName, CompressionLevel.NoCompression);
}

#endregion
Expand Down Expand Up @@ -1759,17 +1752,17 @@ private static string GetLanguageFileLocation()
// get the data directory
dir = Path.Combine(dir, "data");
if (!Directory.Exists(dir))
throw new DirectoryNotFoundException(Format("The path {0} is not valid.", dir));
throw new DirectoryNotFoundException($"The path {dir} is not valid.");

// get the options directory
dir = Path.Combine(dir, "options");
if (!Directory.Exists(dir))
throw new DirectoryNotFoundException(Format("The path {0} is not valid.", dir));
throw new DirectoryNotFoundException($"The path {dir} is not valid.");

// get the languages.yaml file
var langFile = Path.Combine(dir, "languages.yaml");
if (!File.Exists(langFile))
throw new FileNotFoundException(Format("The file {0} was not found.", langFile), langFile);
throw new FileNotFoundException($"The file {langFile} was not found.", langFile);

return langFile;
}
Expand Down Expand Up @@ -1815,12 +1808,12 @@ private Dictionary<string, string> GetLanguageList()
/// ------------------------------------------------------------------------------------
public string GetLanguageName(string iso3Code)
{
var langs = GetLanguageList();
var languages = GetLanguageList();

if (langs == null)
if (languages == null)
throw new Exception("The language list for RAMP was not retrieved.");

return langs.ContainsKey(iso3Code) ? langs[iso3Code] : null;
return languages.TryGetValue(iso3Code, out var lang) ? lang : null;
}
#endregion

Expand Down
3 changes: 2 additions & 1 deletion SIL.Archiving/SIL.Archiving.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DotNetZip" Version="1.16.0" />
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1" PrivateAssets="all" />
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="SIL.ReleaseTasks" Version="2.5.0" PrivateAssets="All" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>
Expand Down
15 changes: 6 additions & 9 deletions SIL.DblBundle.Tests/BundleTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Xml.Serialization;
using Ionic.Zip;
using NUnit.Framework;
using SIL.DblBundle.Text;
using SIL.IO;
Expand Down Expand Up @@ -33,10 +33,7 @@ public TestBundle(string pathToZippedBundle) : base(pathToZippedBundle)
{
}

public override string Name
{
get { return "Test"; }
}
public override string Name => "Test";
}

/// <summary>
Expand Down Expand Up @@ -65,14 +62,14 @@ public void LanguageIso_NoLanguageCodeSpecified_ReturnsCodeForUnlistedLanguage()

private static TempFile CreateDummyVersion1_5ZippedTestBundle()
{
TempFile bundle = TempFile.WithExtension(DblBundleFileUtils.kDblBundleExtension);
var bundle = TempFile.WithExtension(DblBundleFileUtils.kDblBundleExtension);
RobustFile.Delete(bundle.Path);

using (var metadataXml = TempFile.WithFilename("metadata.xml"))
using (var zip = new ZipFile())
using (var zip = ZipFile.Open(bundle.Path, ZipArchiveMode.Create))
{
File.WriteAllText(metadataXml.Path, @"<?xml version=""1.0"" encoding=""utf-8""?><DBLMetadata type=""text"" typeVersion=""1.5""></DBLMetadata>");
zip.AddFile(metadataXml.Path, string.Empty);
zip.Save(bundle.Path);
zip.CreateEntryFromFile(metadataXml.Path, Path.GetFileName(metadataXml.Path));
}

return bundle;
Expand Down
2 changes: 1 addition & 1 deletion SIL.DblBundle.Tests/SIL.DblBundle.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="DotNetZip" Version="1.16.0" />
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.2" PrivateAssets="All" />
<PackageReference Include="SIL.ReleaseTasks" Version="2.5.0" PrivateAssets="All" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />

</ItemGroup>

Expand Down
Loading

0 comments on commit 6baf806

Please sign in to comment.