Skip to content

Commit

Permalink
Fixed music, screenshot and saves path for Mac bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrdacor committed Jun 16, 2022
1 parent 5b23592 commit ae5f36a
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Ambermoon.Core/UI/Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ void ToggleFullscreen()
{
game.Configuration.Fullscreen = !game.Configuration.Fullscreen;

listBox.SetItemAction(3, game.Configuration.Fullscreen ? null : toggleResolutionAction);
listBox.SetItemAction(2, game.Configuration.Fullscreen ? null : toggleResolutionAction);

if (!game.Configuration.Fullscreen)
SetResolution();
Expand Down
30 changes: 30 additions & 0 deletions Ambermoon.net/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,36 @@ public AdditionalSavegameSlots GetOrCreateCurrentAdditionalSavegameSlots()
public static readonly string FallbackConfigDirectory =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ambermoon");

/// <summary>
/// The folder path where the bundle is located.
///
/// If not on Mac this is identical to <see cref="ExecutableDirectoryPath"/>.
/// </summary>
public static string BundleDirectory
{
get
{
if (!OperatingSystem.IsMacOS())
return ExecutableDirectoryPath;

var bundleDirectory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); // "MacOS"
bundleDirectory = Path.GetDirectoryName(bundleDirectory.TrimEnd('/')); // "Contents"
bundleDirectory = Path.GetDirectoryName(bundleDirectory); // "Ambermoon.net.app"
bundleDirectory = Path.GetDirectoryName(bundleDirectory); // folder which contains the bundle

return bundleDirectory;
}
}

/// <summary>
/// Directory path where the executable is located.
///
/// On Windows this will consider build pathes of Visual Studio.
/// In that case the directory of the project file is used.
///
/// If the application is running via dotnet CLI, the correct
/// directory of the exe or dll will still be returned.
/// </summary>
public static string ExecutableDirectoryPath
{
get
Expand Down
31 changes: 24 additions & 7 deletions Ambermoon.net/GameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void Keyboard_KeyDown(IKeyboard keyboard, Silk.NET.Input.Key key, int value)
keyboard.IsKeyPressed(Silk.NET.Input.Key.ControlRight)))))
{
var imageData = renderView.TakeScreenshot();
string directory = Path.Combine(Configuration.ExecutableDirectoryPath, "Screenshots");
string directory = Path.Combine(Configuration.BundleDirectory, "Screenshots");
string path;
static string GetFileName() => "Screenshot_" + DateTime.Now.ToString("dd-MM-yyyy.HH-mm-ss");
try
Expand Down Expand Up @@ -886,7 +886,7 @@ bool ShowVersionSelector(BinaryReader builtinVersionReader, Action<IGameData, st
}

var gameData = new GameData();
var dataPath = configuration.UseDataPath ? configuration.DataPath : Configuration.ExecutableDirectoryPath;
var dataPath = configuration.UseDataPath ? configuration.DataPath : Configuration.BundleDirectory;

if (versions == null || versions.Count == 0)
{
Expand Down Expand Up @@ -1071,14 +1071,14 @@ string GetSavePath(string version)

try
{
var path = Path.Combine(Configuration.ExecutableDirectoryPath, suffix);
var path = Path.Combine(Configuration.BundleDirectory, suffix);
try
{
Directory.CreateDirectory(path);
}
catch
{
path = Path.Combine(Configuration.ExecutableDirectoryPath, alternativeSuffix);
path = Path.Combine(Configuration.BundleDirectory, alternativeSuffix);
Directory.CreateDirectory(path);
}
return path;
Expand Down Expand Up @@ -1192,9 +1192,26 @@ void Window_Load()

if (ShowVersionSelector(builtinVersionReader, (gameData, savePath, gameLanguage, features) =>
{
builtinVersionReader?.Dispose();
renderView?.Dispose();
StartGame(gameData as GameData, savePath, gameLanguage, features);
try
{
builtinVersionReader?.Dispose();
renderView?.Dispose();
}
catch
{
// ignore
}

try
{
StartGame(gameData as GameData, savePath, gameLanguage, features);
}
catch (Exception ex)
{
Console.WriteLine("Error starting game: " + ex.ToString());
window.Close();
return;
}
WindowMoved();
versionSelector = null;
}, out var textureAtlasManager))
Expand Down
5 changes: 4 additions & 1 deletion Ambermoon.net/MusicManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ void LoadExternalSongs()

try
{
string musicPath = Path.Combine(Configuration.ExecutableDirectoryPath, "music");
string musicPath = Path.Combine(Configuration.BundleDirectory, "music");

if (!Directory.Exists(musicPath) && OperatingSystem.IsMacOS())
musicPath = Path.Combine(Configuration.ExecutableDirectoryPath, "music");

if (!Directory.Exists(musicPath))
return;
Expand Down
9 changes: 9 additions & 0 deletions Ambermoon.net/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ static void Main()
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

try
{
Environment.CurrentDirectory = Configuration.ExecutableDirectoryPath;
}
catch
{
// ignore
}

var configuration = LoadConfig();
configuration.UpgradeAdditionalSavegameSlots();
var gameWindow = new GameWindow();
Expand Down
1 change: 0 additions & 1 deletion Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ GraphicFilter | Graphic filter to use | None, Smooth, Blur | None
GraphicFilterOverlay | Overlay to use | None, Lines, Grid, Scanlines, CRT | None
Effects | Additional graphic effects to use | None, Grayscale, Sepia | None
ExtendedSavegameSlots | Enables additional 20 savegame slots | true or false | true
ContinueSavegameSlot | If extended savegame slots are used, this states which slot is the one to continue | null or 0 to 29 | null

Note that the names of the additional savegame slots are stored inside the configuration file as well. The secion is called AdditionalSavegameSlots. The first 10 slots are stored in a binary file called Saves instead. This binary file is compatible with the original Amiga game which only has 10 savegame slots.

Expand Down

0 comments on commit ae5f36a

Please sign in to comment.