Skip to content

Commit

Permalink
Fix more SIQuester errors
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirKhil committed Nov 27, 2023
1 parent caec400 commit b947066
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Authors>Vladimir Khil</Authors>
<Company>Khil-soft</Company>
<SIGameVersion>7.10.0</SIGameVersion>
<SIQuesterVersion>5.11.2</SIQuesterVersion>
<SIQuesterVersion>5.11.3</SIQuesterVersion>
<SImulatorVersion>2.14.0</SImulatorVersion>
</PropertyGroup>

Expand Down
4 changes: 4 additions & 0 deletions src/Common/SIPackages/ContentItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ public void WriteXml(XmlWriter writer)
{
writer.WriteAttributeString("placement", _placement);
}
else if (_type == ContentTypes.Audio || _type == AtomTypes.Audio) // For backward compatibility; remove later
{
writer.WriteAttributeString("placement", GetDefaultPlacement());
}

if (_duration != DefaultDuration)
{
Expand Down
5 changes: 4 additions & 1 deletion src/SIQuester/SIQuester.ViewModel/Items/ThemeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ private void AddQuestion_Executed(object? arg)
var questionViewModel = new QuestionViewModel(question);
Questions.Add(questionViewModel);

QDocument.ActivatedObject = questionViewModel.Scenario.FirstOrDefault();
QDocument.ActivatedObject = IsUpgraded
? questionViewModel.Parameters?.FirstOrDefault().Value.ContentValue?.FirstOrDefault()
: questionViewModel.Scenario.FirstOrDefault();

document.Navigate.Execute(questionViewModel);
}
catch (Exception exc)
Expand Down
27 changes: 20 additions & 7 deletions src/SIQuester/SIQuester.ViewModel/Workspaces/QDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ internal void ClearLinks(QuestionViewModel question)
{
ClearLinks(atom);
}

foreach (var content in question.Model.GetContent())
{
ClearLinks(content);
}
}

internal void ClearLinks(AtomViewModel atom)
Expand Down Expand Up @@ -1285,7 +1290,7 @@ internal QDocument(
StorageContext = storageContextViewModel;

ImportSiq = new SimpleCommand(ImportSiq_Executed);

Save = new AsyncCommand(Save_Executed);
SaveAs = new AsyncCommand(SaveAs_Executed);
SaveAsTemplate = new AsyncCommand(SaveAsTemplate_Executed);
Expand All @@ -1306,7 +1311,7 @@ internal QDocument(
ConvertToMillionaire = new SimpleCommand(ConvertToMillionaire_Executed);
ConvertToSportSI = new SimpleCommand(ConvertToSportSI_Executed);

Wikify = new SimpleCommand(Wikify_Executed);
Wikify = new SimpleCommand(Wikify_Executed);

Navigate = new SimpleCommand(Navigate_Executed);

Expand Down Expand Up @@ -1413,7 +1418,7 @@ private ICollection<string> FillFiles(MediaStorageViewModel mediaStorage, int ma
{
warnings.Add(new WarningViewModel(string.Format(Resources.FileIsDuplicated, name), () => NavigateToStorageItem(mediaStorage, item)));
}

if (AppSettings.Default.CheckFileSize && mediaStorage.GetLength(item.Model.Name) > maxFileSize * 1024)
{
warnings.Add(new WarningViewModel(string.Format(Resources.MediaFileTooLarge, name, maxFileSize), () => NavigateToStorageItem(mediaStorage, item)));
Expand All @@ -1436,7 +1441,7 @@ internal void NavigateToStorageItem(MediaStorageViewModel mediaStorage, MediaIte
/// Checks missing and unused files in document.
/// </summary>
/// <param name="allowExternal">Allow external files to be used.</param>
internal (IEnumerable<WarningViewModel>,string) CheckLinks(bool allowExternal = false)
internal (IEnumerable<WarningViewModel>, string) CheckLinks(bool allowExternal = false)
{
var warnings = new List<WarningViewModel>();
var errors = new List<string>();
Expand All @@ -1453,7 +1458,7 @@ internal void NavigateToStorageItem(MediaStorageViewModel mediaStorage, MediaIte
foreach (var item in images.Except(usedImages))
{
warnings.Add(
new WarningViewModel(string.Format(Resources.UnusedFile, item),
new WarningViewModel(string.Format(Resources.UnusedFile, item),
() => NavigateToStorageItem(Images, Images.Files.FirstOrDefault(f => f.Model.Name == item))));
}

Expand Down Expand Up @@ -2963,6 +2968,14 @@ private void WikifyAsync()
}
}

foreach (var item in quest.Model.GetContent())
{
if (item.Type == ContentTypes.Text)
{
item.Value = item.Value.Wikify();
}
}

for (int i = 0; i < quest.Right.Count; i++)
{
var value = quest.Right[i];
Expand Down Expand Up @@ -3044,7 +3057,7 @@ private void ConvertToCompTvSI_Executed(object? arg)
allthemes.Add(theme);
}
}

while (Package.Rounds.Count > 0)
{
Package.Rounds.RemoveAt(0);
Expand Down Expand Up @@ -3685,7 +3698,7 @@ internal void RestoreFromFolder(DirectoryInfo folder)
Package.Tags.Merge(package.Tags);

Package.Model.Language = package.Language;
Package.Model.Publisher= package.Publisher;
Package.Model.Publisher = package.Publisher;
Package.Model.Date = package.Date;
Package.Model.Difficulty = package.Difficulty;
Package.Model.Name = package.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public sealed class MediaStorageViewModel : WorkspaceViewModel
{
private readonly QDocument _document;

private readonly int _internalId = Random.Shared.Next();

/// <summary>
/// Добавленные файлы
/// </summary>
Expand Down Expand Up @@ -619,6 +621,7 @@ internal long GetLength(string link) =>
return collection.GetFileLength(link);
});

// TODO: switch from IMedia to MediaInfo struct
internal IMedia Wrap(string link)
{
var pendingStream = _streams.FirstOrDefault(n => n.Key.Model.Name == link);
Expand All @@ -631,10 +634,10 @@ internal IMedia Wrap(string link)
return _document.Lock.WithLock(
() =>
{
var collection = _document.GetInternalCollection(_name);

var collection = _document.GetInternalCollection(_name); // This value cannot be cached as internal collection link can eventually change
return PlatformManager.Instance.PrepareMedia(
new Media(() => collection.GetFile(link), () => collection.GetFileLength(link), /*Uri.EscapeDataString(_document.Path) + _document.Package.Model.ID +*/ link),
new Media(() => collection.GetFile(link), () => collection.GetFileLength(link), _internalId + link),
collection.Name);
});
}
Expand Down

0 comments on commit b947066

Please sign in to comment.