Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirKhil committed Feb 12, 2024
1 parent 0c3a848 commit 4dbe2bc
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 102 deletions.
4 changes: 2 additions & 2 deletions src/SIQuester/SIQuester.ViewModel/ContentItemsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ internal ContentItemViewModel Add(string contentType, string value, string place
return contentItem;
}

protected override void OnCurrentItemChanged(ContentItemViewModel oldValue, ContentItemViewModel newValue)
protected override void OnCurrentItemChanged(ContentItemViewModel? oldValue, ContentItemViewModel? newValue)
{
base.OnCurrentItemChanged(oldValue, newValue);

Expand Down Expand Up @@ -503,7 +503,7 @@ private bool AddContentFile(string contentType)
Duration = document.GetDurationByContentType(contentType),
});

Insert(index + 1, contentItemViewModel);
Insert(index + 1 + (i - initialItemCount), contentItemViewModel);

var file = collection.Files[i];

Expand Down
11 changes: 7 additions & 4 deletions src/SIQuester/SIQuester.ViewModel/Model/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ public FileHistory History
{
if (_history != value)
{
_history.Files.CollectionChanged -= CollectionChanged;
_history = value;
_history.Files.CollectionChanged += CollectionChanged;
OnPropertyChanged();
}
}
Expand Down Expand Up @@ -247,9 +249,9 @@ public CostSetterList CostSetters
{
if (_costSetters != value)
{
_costSetters.CollectionChanged -= CostSetters_CollectionChanged;
_costSetters.CollectionChanged -= CollectionChanged;
_costSetters = value;
_costSetters.CollectionChanged += CostSetters_CollectionChanged;
_costSetters.CollectionChanged += CollectionChanged;
OnPropertyChanged();
}
}
Expand Down Expand Up @@ -593,10 +595,11 @@ public static AppSettings Load(Stream stream)

public AppSettings()
{
_costSetters.CollectionChanged += CostSetters_CollectionChanged;
_costSetters.CollectionChanged += CollectionChanged;
_history.Files.CollectionChanged += CollectionChanged;
}

private void CostSetters_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) => HasChanges = true;
private void CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) => HasChanges = true;

public static AppSettings Create()
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/SImulator/SImulator.ViewModel/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<value>Соединение с демонстрационным компьютером было разорвано. Игра прекращена.</value>
</data>
<data name="GamePackageLoadError" xml:space="preserve">
<value>Ошибка при загрузке игрового пакета: {0}</value>
<value>Ошибка при загрузке игрового пакета</value>
</data>
<data name="GameStartError" xml:space="preserve">
<value>Ошибка старта игры: {0}</value>
Expand All @@ -144,6 +144,9 @@
<data name="LoggerCreationWarning" xml:space="preserve">
<value>Ошибка создания файла лога: {0}. Лог записываться не будет</value>
</data>
<data name="LoggerInitError" xml:space="preserve">
<value>Ошибка старта записи лога</value>
</data>
<data name="LogsFolderNotSetWarning" xml:space="preserve">
<value>Папка для записи логов не задана! Логи вестись не будут</value>
</data>
Expand All @@ -159,6 +162,9 @@
<data name="OpenLicensesError" xml:space="preserve">
<value>Ошибка при открытии папки лицензий: {0}</value>
</data>
<data name="PackagePreparationError" xml:space="preserve">
<value>Ошибка подготовки пакета</value>
</data>
<data name="Pause" xml:space="preserve">
<value>Приостановить</value>
</data>
Expand Down
56 changes: 41 additions & 15 deletions src/SImulator/SImulator.ViewModel/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,25 @@ private async Task<SIDocument> PreparePackageAsync(CancellationToken cancellatio
var (filePath, isTemporary) = await _packageSource.GetPackageFileAsync(cancellationToken);

var tempDir = Path.Combine(Path.GetTempPath(), AppSettings.AppName, Guid.NewGuid().ToString());
SIDocument document;

var document = await SIDocument.ExtractToFolderAndLoadAsync(
filePath,
tempDir,
cancellationToken: cancellationToken);

if (isTemporary)
try
{
File.Delete(filePath);
document = await SIDocument.ExtractToFolderAndLoadAsync(
filePath,
tempDir,
cancellationToken: cancellationToken);
}
catch (Exception exc)
{
throw new Exception($"Extraction error. Extraction path: {tempDir}", exc);
}
finally
{
if (isTemporary)
{
File.Delete(filePath);
}
}

return document;
Expand All @@ -375,7 +385,7 @@ private EngineOptions GetEngineOptions()
};
}

private IGameLogger CreateLogger()
private IGameLogger CreateGameLogger()
{
if (Settings.SaveLogs)
{
Expand Down Expand Up @@ -424,7 +434,16 @@ private async Task Start_Executed(object? _)
_start.CanBeExecuted = false;
IsStarting = true;

var document = await PreparePackageAsync(_cancellationTokenSource.Token);
SIDocument document;

try
{
document = await PreparePackageAsync(_cancellationTokenSource.Token);
}
catch (Exception exc)
{
throw new Exception(Resources.PackagePreparationError, exc);
}

ISIEngine engine;

Expand All @@ -443,7 +462,7 @@ private async Task Start_Executed(object? _)
}
catch (Exception exc)
{
throw new Exception(string.Format(Resources.GamePackageLoadError, exc.Message));
throw new Exception(Resources.GamePackageLoadError, exc);
}

var presentationListener = new PresentationListener(engine);
Expand All @@ -457,15 +476,24 @@ private async Task Start_Executed(object? _)
presentationController.UpdateShowPlayers(SettingsViewModel.Model.ShowPlayers);
presentationController.Error += ShowError;

var logger = CreateLogger();
IGameLogger gameLogger;

try
{
gameLogger = CreateGameLogger();
}
catch (Exception exc)
{
throw new Exception(Resources.LoggerInitError, exc);
}

var game = new GameViewModel(
SettingsViewModel,
engine,
presentationListener,
presentationController,
Players,
logger);
gameLogger);

Game = game;

Expand All @@ -492,9 +520,7 @@ private async Task Start_Executed(object? _)
}
catch (Exception exc)
{
var reason = exc.InnerException ?? exc;

PlatformManager.Instance.ShowMessage(string.Format(Resources.GameStartError, reason.Message), false);
PlatformManager.Instance.ShowMessage(string.Format(Resources.GameStartError, exc), false);

_game?.CloseMainView();

Expand Down
Loading

0 comments on commit 4dbe2bc

Please sign in to comment.