SHA256
forked from ADOFAIEditorForum/ADOFAIRenderer
Compare commits
17
Commits
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
51626f65c7
|
||
|
|
65669d5afd
|
||
|
|
5929b5ddbe
|
||
|
|
a7c64e6c27
|
||
|
|
36c569057c
|
||
|
|
b05e18c8bb
|
||
|
|
888663aa86
|
||
|
|
1a8fcaec7d
|
||
|
|
394fe00b25
|
||
|
|
48a56cd3f2
|
||
|
|
63f38883c8
|
||
|
|
24ec6aa1d0
|
||
|
|
44caf92ada | ||
|
|
b3e50cd50e
|
||
|
|
1d4b1cdd46
|
||
|
|
98cf00578d | ||
|
|
5e9c0272dd
|
No files matched your search
+5
-13
@@ -364,9 +364,10 @@ internal class RenderManager : MonoBehaviour
|
||||
|
||||
private IEnumerator SetupPlay()
|
||||
{
|
||||
if (Configuration.AudioConfig.RenderAudio && Configuration.VideoConfig.Codec is Codec.VP9 or Codec.AV1 or Codec.VVC)
|
||||
if (Configuration.AudioConfig.RenderAudio)
|
||||
{
|
||||
Configuration.AudioConfig.AudioSampleRate = 48000;
|
||||
if (!CodecUtil.AvailableSampleRate[CodecUtil.AudioCodecMatch[Configuration.VideoConfig.Codec]].Contains(Configuration.AudioConfig.AudioSampleRate))
|
||||
Configuration.AudioConfig.AudioSampleRate = 48000; // most compatible value
|
||||
}
|
||||
|
||||
for (; countdown > 0; countdown--)
|
||||
@@ -463,7 +464,7 @@ internal class RenderManager : MonoBehaviour
|
||||
try
|
||||
{
|
||||
var effectiveVideoFps = Math.Min(videoFPS, renderFPS);
|
||||
var codecId = AudioCodecMatch[Configuration.VideoConfig.Codec];
|
||||
var codecId = CodecUtil.AudioCodecMatch[Configuration.VideoConfig.Codec];
|
||||
var settings = new FFmpegNativeEncoder.EncoderSettings
|
||||
{
|
||||
Width = Configuration.RenderWidth,
|
||||
@@ -775,7 +776,7 @@ internal class RenderManager : MonoBehaviour
|
||||
_frameReader?.Dispose();
|
||||
AudioMixer?.Reset(); AudioMixer = null;
|
||||
SyncCalculator.Reset();
|
||||
|
||||
|
||||
RenderContext.Reset();
|
||||
|
||||
ADOBase.loader.LoadSceneWithTransition(WipeDirection.StartsFromRight, "scnEditor");
|
||||
@@ -816,13 +817,4 @@ internal class RenderManager : MonoBehaviour
|
||||
Melon<RenderMod>.Logger.Error($"OnLastUpdate callback caused error: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Dictionary<Codec, AVCodecID> AudioCodecMatch = new()
|
||||
{
|
||||
[Codec.H264] = AVCodecID.AV_CODEC_ID_AAC,
|
||||
[Codec.H265] = AVCodecID.AV_CODEC_ID_AAC,
|
||||
[Codec.VP9] = AVCodecID.AV_CODEC_ID_OPUS,
|
||||
[Codec.AV1] = AVCodecID.AV_CODEC_ID_OPUS,
|
||||
[Codec.VVC] = AVCodecID.AV_CODEC_ID_OPUS
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using ADOFAIRenderer.Util.FFmpeg;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ADOFAIRenderer.Data;
|
||||
|
||||
@@ -16,7 +17,7 @@ public class RenderConfig
|
||||
public AudioEncodingConfig AudioConfig { get; set; } = new();
|
||||
public AdvancedConfig AdvancedConfig { get; set; } = new();
|
||||
|
||||
public double DelayAfterEnd { get; set; }
|
||||
public double DelayAfterEnd { get; set; } = 15;
|
||||
public bool ShowJudgementText { get; set; } = false;
|
||||
}
|
||||
|
||||
@@ -27,6 +28,10 @@ public class AdvancedConfig
|
||||
public bool ProcessAudio { get; set; } = true;
|
||||
public bool NonTile { get; set; } = false;
|
||||
public string FileExtension { get; set; } = "mkv";
|
||||
|
||||
public Color? firePlanetColor = null;
|
||||
public Color? icePlanetColor = null;
|
||||
public Color? windPlanetColor = null;
|
||||
}
|
||||
|
||||
public class VideoEncodingConfig
|
||||
@@ -44,7 +49,7 @@ public class VideoEncodingConfig
|
||||
|
||||
public class AudioEncodingConfig
|
||||
{
|
||||
private int _audioSampleRate = 44100;
|
||||
private int _audioSampleRate = 48000;
|
||||
private int _audioChannels = 2;
|
||||
private int _audioBitrate = 256000;
|
||||
|
||||
@@ -52,8 +57,8 @@ public class AudioEncodingConfig
|
||||
|
||||
public int AudioSampleRate
|
||||
{
|
||||
get => _audioSampleRate <= 0 ? 44100 : _audioSampleRate;
|
||||
set => _audioSampleRate = value <= 0 ? 44100 : value;
|
||||
get => _audioSampleRate <= 0 ? 48000 : _audioSampleRate;
|
||||
set => _audioSampleRate = value <= 0 ? 48000 : value;
|
||||
}
|
||||
|
||||
public int AudioChannels
|
||||
|
||||
@@ -31,5 +31,6 @@
|
||||
"ui.render_config.random_seed": "Random Seed (Optional)",
|
||||
"ui.render_config.validation_title": "Invalid Settings",
|
||||
"ui.render_config.validation_error": "Please check your input values:\n- Width and Height must be integers > 0\n- Render FPS and Video FPS must be > 0\n- Delay After End must be >= 0",
|
||||
"ui.render_config.invalid_path": "Output directory path is invalid:\n{0}"
|
||||
"ui.render_config.invalid_path": "Output directory path is invalid:\n{0}",
|
||||
"ui.render_config.expired": "(Expired)"
|
||||
}
|
||||
@@ -31,5 +31,6 @@
|
||||
"ui.render_config.random_seed": "랜덤 시드 (선택 사항)",
|
||||
"ui.render_config.validation_title": "설정 오류",
|
||||
"ui.render_config.validation_error": "입력값을 확인해 주세요:\n- 너비와 높이는 0보다 큰 정수여야 합니다.\n- 렌더 FPS와 영상 FPS는 0보다 커야 합니다.\n- 종료 후 대기 시간은 0 이상이어야 합니다.",
|
||||
"ui.render_config.invalid_path": "출력 디렉토리 경로가 올바르지 않습니다:\n{0}"
|
||||
"ui.render_config.invalid_path": "출력 디렉토리 경로가 올바르지 않습니다:\n{0}",
|
||||
"ui.render_config.expired": "(만료됨)"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using ADOFAIRenderer.Core;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ADOFAIRenderer.Patch.Game;
|
||||
|
||||
[HarmonyPatch(typeof(PlanetRenderer))]
|
||||
public static class PlanetRendererPatch
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch("SetColor")]
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private static void OverrideColor(PlanetRenderer __instance, ref PlanetColor planetColor)
|
||||
{
|
||||
if (RenderManager.Instance.stage == RenderStage.None) return;
|
||||
|
||||
var advConf = RenderManager.Instance.Configuration.AdvancedConfig;
|
||||
ApplyColor(ref planetColor, scrController.instance.planetRed, advConf.firePlanetColor);
|
||||
ApplyColor(ref planetColor, scrController.instance.planetBlue, advConf.icePlanetColor);
|
||||
ApplyColor(ref planetColor, scrController.instance.planetGreen, advConf.windPlanetColor);
|
||||
|
||||
return;
|
||||
|
||||
void ApplyColor(ref PlanetColor planetColor, scrPlanet? targetPlanet, Color? customColor)
|
||||
{
|
||||
if (targetPlanet != null && __instance == targetPlanet.planetRenderer && customColor != null)
|
||||
planetColor = new PlanetColor(customColor.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -9,7 +9,7 @@ using MelonLoader.Utils;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
[assembly: MelonInfo(typeof(RenderMod), "ADOFAI Renderer", "0.3.3-BETA", "ADOFAI Editor Forum")]
|
||||
[assembly: MelonInfo(typeof(RenderMod), "ADOFAI Renderer", "0.2.1-INDEV", "ADOFAI Editor Forum")]
|
||||
[assembly: MelonGame("7th Beat Games", "A Dance of Fire and Ice")]
|
||||
|
||||
namespace ADOFAIRenderer;
|
||||
@@ -18,7 +18,7 @@ internal class RenderMod : MelonMod
|
||||
{
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public static bool IsFeatureDisabled = false;
|
||||
public static DateTime ExpirationTime = new(2026, 09, 21, 0, 0, 0, DateTimeKind.Utc);
|
||||
public static DateTime ExpirationTime = new(2026, 11, 21, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
public override void OnInitializeMelon()
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+23
-1
@@ -80,7 +80,29 @@ internal class RendererUIManager : MonoBehaviour
|
||||
MiddleClickToDefault = true,
|
||||
SliderSensitivity = 1.0f
|
||||
},
|
||||
theme: O5Theme.Dark,
|
||||
theme: O5Theme.Dark with
|
||||
{
|
||||
PanelBG = new Color(0.067f, 0.067f, 0.067f, 1f),
|
||||
TopBar = new Color(0f, 0f, 0f, 0.6f),
|
||||
MenuBG = new Color(0f, 0f, 0f, 0.6f),
|
||||
MenuHover = new Color(1.000f, 0.294f, 0.079f, .6f),
|
||||
ObjectBG = new Color(0f, 0f, 0f, 1f),
|
||||
ObjectButton = new Color(0f, 0f, 0f, 1f),
|
||||
ObjectActive = new Color(1.000f, 0.294f, 0.079f, 1f),
|
||||
ObjectActiveBright = new Color(0.812f, 0.827f, 1.000f, 1f),
|
||||
ControlOutlineIdle = new Color(1f, 1f, 1f, 0.4f),
|
||||
ButtonHover = new Color(0.133f, 0.133f, 0.133f, 1.0f),
|
||||
ControlOutlineHover = new Color(1f, 1f, 1f, 0.4f),
|
||||
CardHeader = new Color(0.157f, 0f, 0f, 1f),
|
||||
CardPanel = new Color(0, 0, 0, 0f),
|
||||
SoftRed = new Color(1.000f, 0.576f, 0.590f, 1f),
|
||||
MathOk = new Color(0.408f, 0.827f, 0.569f, 1f),
|
||||
MathWarn = new Color(0.964f, 0.647f, 0.315f, 1f),
|
||||
MathErr = new Color(1.000f, 0.576f, 0.590f, 1f),
|
||||
CornerRadius = 12, OutlineWidth = 2, ControlHeight = 40, FontSizeBody = 18, FontSizeH1 = 48,
|
||||
Outline = new Color(1f, 1f, 1f, 0.2f),
|
||||
TextDimAlpha = 1f
|
||||
},
|
||||
fonts: new RendererFontProvider()
|
||||
);
|
||||
|
||||
|
||||
+194
-152
@@ -1,12 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ADOFAIRenderer.API;
|
||||
using ADOFAIRenderer.Core;
|
||||
using ADOFAIRenderer.Data;
|
||||
using ADOFAIRenderer.Localization;
|
||||
using ADOFAIRenderer.Util;
|
||||
using ADOFAIRenderer.Util.FFmpeg;
|
||||
using HarmonyLib;
|
||||
using MelonLoader;
|
||||
using O5Kit.Control;
|
||||
using O5Kit.Core;
|
||||
@@ -21,11 +23,11 @@ internal static class RenderConfigWindow
|
||||
private static O5Window? _configWindow;
|
||||
|
||||
// Controls cache for validation & sync
|
||||
private static O5InputField? _renderFpsInput;
|
||||
private static O5InputField? _videoFpsInput;
|
||||
private static O5InputField? _renderWidthInput;
|
||||
private static O5InputField? _renderHeightInput;
|
||||
private static O5InputField? _delayAfterEndInput;
|
||||
private static O5Slider? _renderFpsSlider;
|
||||
private static O5Slider? _videoFPSSlider;
|
||||
private static O5Slider? _renderWidthSlider;
|
||||
private static O5Slider? _renderHeightSlider;
|
||||
private static O5Slider? _delayAfterEndSlider;
|
||||
private static O5Toggle? _showJudgementToggle;
|
||||
|
||||
private static O5Dropdown<Codec>? _codecDropdown;
|
||||
@@ -33,13 +35,13 @@ internal static class RenderConfigWindow
|
||||
private static O5InputField? _bitrateInput;
|
||||
private static O5InputField? _maxBitrateInput;
|
||||
private static O5InputField? _qpInput;
|
||||
private static O5InputField? _keyframeIntervalInput;
|
||||
private static O5Slider? _keyframeIntervalSlider;
|
||||
private static O5Toggle? _forceSoftwareToggle;
|
||||
|
||||
private static O5Toggle? _renderAudioToggle;
|
||||
private static O5Dropdown<int>? _sampleRateDropdown;
|
||||
private static O5Dropdown<int>? _channelsDropdown;
|
||||
private static O5InputField? _audioBitrateInput;
|
||||
private static O5Slider? _audioBitrateSlider;
|
||||
|
||||
private static O5InputField? _outputDirInput;
|
||||
|
||||
@@ -69,7 +71,8 @@ internal static class RenderConfigWindow
|
||||
|
||||
BuildUI(_configWindow.Content);
|
||||
}
|
||||
|
||||
|
||||
// ReSharper disable once NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract
|
||||
var config = RenderManager.Instance.Configuration ??= new RenderConfig();
|
||||
ApplyConfigToUI(config);
|
||||
|
||||
@@ -83,58 +86,102 @@ internal static class RenderConfigWindow
|
||||
var (viewport, scrollContent, scroller) =
|
||||
O5Factory.ScrollView(ctx, content, spacing: 10f, padding: 8f);
|
||||
|
||||
// ReSharper disable once NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract
|
||||
var config = RenderManager.Instance.Configuration ??= new RenderConfig();
|
||||
EnsureDefaultConfig(config);
|
||||
|
||||
double[] renderFpsSnap = { 23.976, 24, 29.97, 30, 59.94, 60, 144,
|
||||
120, 240, 360, 480, 600, 720, // +120
|
||||
288, 576, 864, 1152, 1440, 1728, // +288
|
||||
3000 // MAX
|
||||
};
|
||||
double[] videoFpsSnap = { 23.976, 24, 29.97, 30, 59.94, 60, 72,
|
||||
120, 180, 240, 300, 360, 420, 480, 540, // +60
|
||||
144, 216, 288, 432, 504, 576, // +72
|
||||
600 // MAX
|
||||
};
|
||||
|
||||
double[] audioBitrateSnap = { 64, 96, 128, 192, 256, 320, 384 };
|
||||
|
||||
double[] renderWidthSnap = {
|
||||
256, 426, 640, 854, 960, 1280, 1366, 1600, 1920, 2048, 2560, 3200, 3840, 4096, 5120, 5760, 6016, 7680, 10240, 15360, // 16:9
|
||||
230, 384, 576, 768, 1152, 1440, 1680, 2880, 3072, // 16:10
|
||||
192, 320, 480, 800, 1024, 1400, 2732, 6400, 11520 // 4:3
|
||||
};
|
||||
|
||||
double[] renderHeightSnap = {
|
||||
144, 240, 360, 480, 540, 720, 768, 900, 1080, 1152, 1440, 1800, 2160, 2304, 2880, 3240, 3384, 4320, 5760, 8640, // 16:9
|
||||
400, 600, 800, 1050, 1200, 1600, 1920, 2400, 3200, 4800, 9600, // 16:10
|
||||
864, 960, 1536, 2048, 3072 // 4:3
|
||||
};
|
||||
|
||||
// TODO: Presets
|
||||
|
||||
// 1-3. Top section: 좌/우 컨테이너 1개씩으로 3행을 쌓는다 (중앙선 1개)
|
||||
var (topLeft, topRight) = CreateTwoColumnPanel(scrollContent, spacing: 8f, columnSpacing: 10f);
|
||||
_renderFpsInput = CreateInputField(
|
||||
ctx, CreateFieldSlot(topLeft),
|
||||
LocalizationManager.Get("ui.render_config.render_fps"),
|
||||
"60", config.RenderFPS.ToString("0.##"),
|
||||
"input_render_fps",
|
||||
TMPro.TMP_InputField.CharacterValidation.Decimal,
|
||||
val => { if (double.TryParse(val, out var d) && d > 0) config.RenderFPS = d; }
|
||||
|
||||
_renderFpsSlider = O5Factory.Slider(
|
||||
ctx: ctx, parent: CreateFieldSlot(topLeft),
|
||||
defaultValue: 60, min: 0.01, max: 3000, value: 60,
|
||||
format: "F3", clampMode: ClampMode.All,
|
||||
|
||||
sliderFilter: value => renderFpsSnap.OrderBy(n => Math.Abs(n - value)).First(),
|
||||
inputFilter: null, onComplete: null, onChanged: val => { config.RenderFPS = val; },
|
||||
text: LocalizationManager.Get("ui.render_config.render_fps"),
|
||||
id: "slider_render_fps", showFill: true
|
||||
);
|
||||
_renderWidthInput = CreateInputField(
|
||||
ctx, CreateFieldSlot(topLeft),
|
||||
LocalizationManager.Get("ui.render_config.render_width"),
|
||||
"1920", config.RenderWidth.ToString(),
|
||||
"input_render_width",
|
||||
TMPro.TMP_InputField.CharacterValidation.Integer,
|
||||
val => { if (int.TryParse(val, out var i) && i > 0) config.RenderWidth = i; }
|
||||
|
||||
_videoFPSSlider = O5Factory.Slider(
|
||||
ctx: ctx, parent: CreateFieldSlot(topRight),
|
||||
defaultValue: 60, min: 0.01, max: 600, value: 60,
|
||||
format: "F3", clampMode: ClampMode.All,
|
||||
|
||||
sliderFilter: value => videoFpsSnap.OrderBy(n => Math.Abs(n - value)).First(),
|
||||
inputFilter: null, onComplete: null, onChanged: val => { config.VideoFPS = val; },
|
||||
text: LocalizationManager.Get("ui.render_config.video_fps"),
|
||||
id: "slider_video_fps", showFill: true
|
||||
);
|
||||
_delayAfterEndInput = CreateInputField(
|
||||
ctx, CreateFieldSlot(topLeft),
|
||||
LocalizationManager.Get("ui.render_config.delay_after_end"),
|
||||
"1.0", config.DelayAfterEnd.ToString("0.##"),
|
||||
"input_delay_after_end",
|
||||
TMPro.TMP_InputField.CharacterValidation.Decimal,
|
||||
val => { if (double.TryParse(val, out var d) && d >= 0) config.DelayAfterEnd = d; }
|
||||
|
||||
_renderWidthSlider = O5Factory.Slider(
|
||||
ctx: ctx, parent: CreateFieldSlot(topLeft),
|
||||
defaultValue: 2560, min: 0, max: 15360, value: 2560,
|
||||
format: "F0", clampMode: ClampMode.All,
|
||||
|
||||
sliderFilter: value => renderWidthSnap.OrderBy(n => Math.Abs(n - value)).First(), inputFilter: value => Math.Max(value, 2),
|
||||
onComplete: null, onChanged: val => { config.RenderWidth = (int)Math.Round(val); },
|
||||
text: LocalizationManager.Get("ui.render_config.render_width"),
|
||||
id: "slider_render_width", showFill: true
|
||||
);
|
||||
_videoFpsInput = CreateInputField(
|
||||
ctx, CreateFieldSlot(topRight),
|
||||
LocalizationManager.Get("ui.render_config.video_fps"),
|
||||
"60", config.VideoFPS.ToString("0.##"),
|
||||
"input_video_fps",
|
||||
TMPro.TMP_InputField.CharacterValidation.Decimal,
|
||||
val => { if (double.TryParse(val, out var d) && d > 0) config.VideoFPS = d; }
|
||||
|
||||
_renderHeightSlider = O5Factory.Slider(
|
||||
ctx: ctx, parent: CreateFieldSlot(topRight),
|
||||
defaultValue: 1440, min: 0, max: 8640, value: 1440,
|
||||
format: "F0", clampMode: ClampMode.All,
|
||||
|
||||
sliderFilter: value => renderHeightSnap.OrderBy(n => Math.Abs(n - value)).First(), inputFilter: value => Math.Max(value, 2),
|
||||
onComplete: null, onChanged: val => { config.RenderWidth = (int)Math.Round(val); },
|
||||
text: LocalizationManager.Get("ui.render_config.render_height"),
|
||||
id: "slider_render_height", showFill: true
|
||||
);
|
||||
_renderHeightInput = CreateInputField(
|
||||
ctx, CreateFieldSlot(topRight),
|
||||
LocalizationManager.Get("ui.render_config.render_height"),
|
||||
"1080", config.RenderHeight.ToString(),
|
||||
"input_render_height",
|
||||
TMPro.TMP_InputField.CharacterValidation.Integer,
|
||||
val => { if (int.TryParse(val, out var i) && i > 0) config.RenderHeight = i; }
|
||||
|
||||
_delayAfterEndSlider = O5Factory.Slider(
|
||||
ctx: ctx, parent: CreateFieldSlot(topLeft),
|
||||
defaultValue: 15, min: 0, max: 9999.999, value: 15,
|
||||
format: "F3", clampMode: ClampMode.All,
|
||||
|
||||
sliderFilter: null, inputFilter: null,
|
||||
onComplete: null, onChanged: val => { config.DelayAfterEnd = val; },
|
||||
text: LocalizationManager.Get("ui.render_config.delay_after_end"),
|
||||
id: "slider_delay_after_end", showFill: true
|
||||
);
|
||||
|
||||
_showJudgementToggle = CreateToggleField(
|
||||
ctx, CreateFieldSlot(topRight),
|
||||
LocalizationManager.Get("ui.render_config.show_judgement"),
|
||||
ctx, CreateFieldSlot(topRight), "",
|
||||
false, config.ShowJudgementText,
|
||||
LocalizationManager.Get("ui.render_config.show_judgement"),
|
||||
"toggle_show_judgement",
|
||||
val => config.ShowJudgementText = val
|
||||
val => config.ShowJudgementText = val,
|
||||
generateLabel: false
|
||||
);
|
||||
|
||||
// 4. Video Encoding Config (Collapsible Card)
|
||||
@@ -156,8 +203,12 @@ internal static class RenderConfigWindow
|
||||
Codec.H264, config.VideoConfig.Codec,
|
||||
codecs, c => c.ToString(),
|
||||
"dd_video_codec",
|
||||
c => config.VideoConfig.Codec = c
|
||||
);
|
||||
c =>
|
||||
{
|
||||
config.VideoConfig.Codec = c;
|
||||
UpdateVideoCodec(c);
|
||||
});
|
||||
|
||||
_bitrateInput = CreateInputField(
|
||||
ctx, CreateFieldSlot(videoLeft),
|
||||
LocalizationManager.Get("ui.render_config.bitrate"),
|
||||
@@ -166,6 +217,7 @@ internal static class RenderConfigWindow
|
||||
TMPro.TMP_InputField.CharacterValidation.Integer,
|
||||
val => { if (int.TryParse(val, out var b) && b > 0) config.VideoConfig.Bitrate = b; }
|
||||
);
|
||||
|
||||
_qpInput = CreateInputField(
|
||||
ctx, CreateFieldSlot(videoLeft),
|
||||
LocalizationManager.Get("ui.render_config.qp"),
|
||||
@@ -184,6 +236,7 @@ internal static class RenderConfigWindow
|
||||
"dd_rate_control",
|
||||
m => config.VideoConfig.RateControlMode = m
|
||||
);
|
||||
|
||||
_maxBitrateInput = CreateInputField(
|
||||
ctx, CreateFieldSlot(videoRight),
|
||||
LocalizationManager.Get("ui.render_config.max_bitrate"),
|
||||
@@ -192,21 +245,25 @@ internal static class RenderConfigWindow
|
||||
TMPro.TMP_InputField.CharacterValidation.Integer,
|
||||
val => { if (int.TryParse(val, out var mb) && mb > 0) config.VideoConfig.MaxBitrate = mb; }
|
||||
);
|
||||
_keyframeIntervalInput = CreateInputField(
|
||||
ctx, CreateFieldSlot(videoRight),
|
||||
LocalizationManager.Get("ui.render_config.keyframe_interval"),
|
||||
"2.0", config.VideoConfig.KeyframeInterval.ToString("0.##"),
|
||||
"input_keyframe_interval",
|
||||
TMPro.TMP_InputField.CharacterValidation.Decimal,
|
||||
val => { if (double.TryParse(val, out var kf) && kf > 0) config.VideoConfig.KeyframeInterval = kf; }
|
||||
|
||||
_forceSoftwareToggle = CreateToggleField(
|
||||
ctx, CreateFieldSlot(videoRight), "",
|
||||
false, config.VideoConfig.ForceSoftwareEncoder,
|
||||
LocalizationManager.Get("ui.render_config.force_software"),
|
||||
"toggle_force_software",
|
||||
val => config.AudioConfig.RenderAudio = val,
|
||||
generateLabel: true
|
||||
);
|
||||
|
||||
_forceSoftwareToggle = O5Factory.Toggle(
|
||||
ctx, videoContent,
|
||||
false, config.VideoConfig.ForceSoftwareEncoder,
|
||||
val => config.VideoConfig.ForceSoftwareEncoder = val,
|
||||
LocalizationManager.Get("ui.render_config.force_software"),
|
||||
"toggle_force_software"
|
||||
_keyframeIntervalSlider = O5Factory.Slider(
|
||||
ctx: ctx, parent: videoContent,
|
||||
defaultValue: 2, min: 0.1, max: 10, value: 2,
|
||||
format: "F1", clampMode: ClampMode.All,
|
||||
|
||||
sliderFilter: null, inputFilter: null,
|
||||
onComplete: null, onChanged: val => { config.VideoConfig.KeyframeInterval = val; },
|
||||
text: LocalizationManager.Get("ui.render_config.keyframe_interval"),
|
||||
id: "slider_keyframe_interval", showFill: true
|
||||
);
|
||||
|
||||
// 5. Audio Encoding Config (Collapsible Card)
|
||||
@@ -222,13 +279,25 @@ internal static class RenderConfigWindow
|
||||
|
||||
var (audioLeft, audioRight) = CreateTwoColumnPanel(audioContent);
|
||||
_renderAudioToggle = CreateToggleField(
|
||||
ctx, CreateFieldSlot(audioLeft),
|
||||
LocalizationManager.Get("ui.render_config.render_audio"),
|
||||
ctx, CreateFieldSlot(audioLeft), "",
|
||||
true, config.AudioConfig.RenderAudio,
|
||||
LocalizationManager.Get("ui.render_config.render_audio"),
|
||||
"toggle_render_audio",
|
||||
val => config.AudioConfig.RenderAudio = val
|
||||
val => config.AudioConfig.RenderAudio = val,
|
||||
generateLabel: false
|
||||
);
|
||||
|
||||
_audioBitrateSlider = O5Factory.Slider(
|
||||
ctx: ctx, parent: CreateFieldSlot(audioRight),
|
||||
defaultValue: 256, min: 64, max: 384, value: 256,
|
||||
format: "F0", clampMode: ClampMode.All,
|
||||
|
||||
sliderFilter: value => audioBitrateSnap.OrderBy(n => Math.Abs(n - value)).First(),
|
||||
inputFilter: null, onComplete: null, onChanged: val => { config.AudioConfig.AudioBitrate = (int)Math.Round(val) * 1000; },
|
||||
text: LocalizationManager.Get("ui.render_config.audio_bitrate"),
|
||||
id: "slider_audio_bitrate", showFill: true
|
||||
);
|
||||
|
||||
var channels = new[] { 1, 2 };
|
||||
_channelsDropdown = CreateDropdownField(
|
||||
ctx, CreateFieldSlot(audioLeft),
|
||||
@@ -239,23 +308,14 @@ internal static class RenderConfigWindow
|
||||
c => config.AudioConfig.AudioChannels = c
|
||||
);
|
||||
|
||||
var sampleRates = new[] { 44100, 48000 };
|
||||
_sampleRateDropdown = CreateDropdownField(
|
||||
ctx, CreateFieldSlot(audioRight),
|
||||
LocalizationManager.Get("ui.render_config.sample_rate"),
|
||||
44100, config.AudioConfig.AudioSampleRate,
|
||||
sampleRates, r => $"{r} Hz",
|
||||
48000, config.AudioConfig.AudioSampleRate,
|
||||
CodecUtil.AvailableSampleRate[CodecUtil.AudioCodecMatch[config.VideoConfig.Codec]], r => $"{r/1000.0} kHz",
|
||||
"dd_sample_rate",
|
||||
r => config.AudioConfig.AudioSampleRate = r
|
||||
);
|
||||
_audioBitrateInput = CreateInputField(
|
||||
ctx, CreateFieldSlot(audioRight),
|
||||
LocalizationManager.Get("ui.render_config.audio_bitrate"),
|
||||
"256", (config.AudioConfig.AudioBitrate / 1000).ToString(),
|
||||
"input_audio_bitrate",
|
||||
TMPro.TMP_InputField.CharacterValidation.Integer,
|
||||
val => { if (int.TryParse(val, out var ab) && ab > 0) config.AudioConfig.AudioBitrate = ab * 1000; }
|
||||
);
|
||||
|
||||
// 6. Global Settings (Collapsible Card)
|
||||
var (_, globalContent) = O5Factory.Card(
|
||||
@@ -299,6 +359,7 @@ internal static class RenderConfigWindow
|
||||
: _outputDirInput.Value;
|
||||
FolderDialogUtil.OpenFolderBrowser(initial, selected =>
|
||||
{
|
||||
Melon<RenderMod>.Logger.Msg("Output Directory Selected: " + selected);
|
||||
if (!string.IsNullOrWhiteSpace(selected))
|
||||
{
|
||||
_outputDirInput.Set(selected);
|
||||
@@ -344,13 +405,14 @@ internal static class RenderConfigWindow
|
||||
"dd_adv_file_extension",
|
||||
e => { if (!string.IsNullOrEmpty(e)) config.AdvancedConfig.FileExtension = e; }
|
||||
);
|
||||
|
||||
_processAudioToggle = CreateToggleField(
|
||||
ctx, CreateFieldSlot(advLeft),
|
||||
LocalizationManager.Get("ui.render_config.process_audio"),
|
||||
ctx, CreateFieldSlot(advLeft), "",
|
||||
true, config.AdvancedConfig.ProcessAudio,
|
||||
LocalizationManager.Get("ui.render_config.process_audio"),
|
||||
"toggle_process_audio",
|
||||
val => config.AdvancedConfig.ProcessAudio = val
|
||||
val => config.AdvancedConfig.ProcessAudio = val,
|
||||
generateLabel: false
|
||||
);
|
||||
|
||||
_randomSeedInput = CreateInputField(
|
||||
@@ -365,14 +427,17 @@ internal static class RenderConfigWindow
|
||||
else if (string.IsNullOrWhiteSpace(val)) config.AdvancedConfig.RandomSeed = null;
|
||||
}
|
||||
);
|
||||
|
||||
_nonTileToggle = CreateToggleField(
|
||||
ctx, CreateFieldSlot(advRight),
|
||||
LocalizationManager.Get("ui.render_config.non_tile"),
|
||||
ctx, CreateFieldSlot(advRight), "",
|
||||
false, config.AdvancedConfig.NonTile,
|
||||
LocalizationManager.Get("ui.render_config.non_tile"),
|
||||
"toggle_non_tile",
|
||||
val => config.AdvancedConfig.NonTile = val
|
||||
val => config.AdvancedConfig.NonTile = val,
|
||||
generateLabel: false
|
||||
);
|
||||
|
||||
// TODO: Fire Planet, Ice Planet, Wind Planet Color Settings (Each Optional)
|
||||
|
||||
// 8. Go Render Button
|
||||
O5Factory.Button(
|
||||
@@ -382,26 +447,47 @@ internal static class RenderConfigWindow
|
||||
"btn_go_render",
|
||||
height: 48f
|
||||
);
|
||||
|
||||
// 9. Version Label
|
||||
var versionLabel = O5Factory.ControlText(ctx, scrollContent, 12f, noPad: true);
|
||||
var versionText = $"ADOFAI Renderer v{Melon<RenderMod>.Instance.Info.Version}";
|
||||
if (DateTime.UtcNow >= RenderMod.ExpirationTime) versionText += " " + LocalizationManager.Get("ui.render_config.expired");
|
||||
|
||||
versionLabel.text = versionText;
|
||||
versionLabel.alignment = TMPro.TextAlignmentOptions.Center;
|
||||
versionLabel.color = ctx.Theme.TextDim;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
var versionLE = versionLabel.gameObject.AddComponent<LayoutElement>();
|
||||
versionLE.preferredHeight = 18f;
|
||||
versionLE.minHeight = 18f;
|
||||
|
||||
return;
|
||||
|
||||
void UpdateVideoCodec(Codec codec)
|
||||
{
|
||||
_sampleRateDropdown?.SetValues(CodecUtil.AvailableSampleRate[CodecUtil.AudioCodecMatch[codec]]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void EnsureDefaultConfig(RenderConfig config)
|
||||
{
|
||||
if (config.RenderWidth <= 0) config.RenderWidth = Screen.width > 0 ? Screen.width : 1920;
|
||||
if (config.RenderHeight <= 0) config.RenderHeight = Screen.height > 0 ? Screen.height : 1080;
|
||||
if (config.RenderWidth <= 0) config.RenderWidth = 2560;
|
||||
if (config.RenderHeight <= 0) config.RenderHeight = 1440;
|
||||
if (config.RenderFPS <= 0) config.RenderFPS = 60.0;
|
||||
if (config.VideoFPS <= 0) config.VideoFPS = 60.0;
|
||||
if (config.DelayAfterEnd < 0) config.DelayAfterEnd = 1.0;
|
||||
if (config.DelayAfterEnd < 0) config.DelayAfterEnd = 15.0;
|
||||
}
|
||||
|
||||
private static void ApplyConfigToUI(RenderConfig config)
|
||||
{
|
||||
EnsureDefaultConfig(config);
|
||||
|
||||
_renderFpsInput?.Set(config.RenderFPS.ToString("0.##"), false);
|
||||
_videoFpsInput?.Set(config.VideoFPS.ToString("0.##"), false);
|
||||
_renderWidthInput?.Set(config.RenderWidth.ToString(), false);
|
||||
_renderHeightInput?.Set(config.RenderHeight.ToString(), false);
|
||||
_delayAfterEndInput?.Set(config.DelayAfterEnd.ToString("0.##"), false);
|
||||
_renderFpsSlider?.Set((float) config.RenderFPS, false);
|
||||
_videoFPSSlider?.Set((float) config.VideoFPS, false);
|
||||
_renderWidthSlider?.Set(config.RenderWidth, false);
|
||||
_renderHeightSlider?.Set(config.RenderHeight, false);
|
||||
_delayAfterEndSlider?.Set((float) config.DelayAfterEnd, false);
|
||||
_showJudgementToggle?.Set(config.ShowJudgementText, false);
|
||||
|
||||
_codecDropdown?.Set(config.VideoConfig.Codec, false);
|
||||
@@ -409,13 +495,13 @@ internal static class RenderConfigWindow
|
||||
_bitrateInput?.Set(config.VideoConfig.Bitrate.ToString(), false);
|
||||
_maxBitrateInput?.Set(config.VideoConfig.MaxBitrate.ToString(), false);
|
||||
_qpInput?.Set(config.VideoConfig.QP.ToString(), false);
|
||||
_keyframeIntervalInput?.Set(config.VideoConfig.KeyframeInterval.ToString("0.##"), false);
|
||||
_keyframeIntervalSlider?.Set(config.VideoConfig.KeyframeInterval, false);
|
||||
_forceSoftwareToggle?.Set(config.VideoConfig.ForceSoftwareEncoder, false);
|
||||
|
||||
_renderAudioToggle?.Set(config.AudioConfig.RenderAudio, false);
|
||||
_sampleRateDropdown?.Set(config.AudioConfig.AudioSampleRate, false);
|
||||
_channelsDropdown?.Set(config.AudioConfig.AudioChannels, false);
|
||||
_audioBitrateInput?.Set((config.AudioConfig.AudioBitrate / 1000).ToString(), false);
|
||||
_audioBitrateSlider?.Set(config.AudioConfig.AudioBitrate / 1000.0, false);
|
||||
|
||||
_outputDirInput?.Set(GlobalSettings.EffectiveOutputDirectory, false);
|
||||
|
||||
@@ -429,46 +515,6 @@ internal static class RenderConfigWindow
|
||||
{
|
||||
var config = RenderManager.Instance.Configuration;
|
||||
|
||||
// Validate RenderFPS
|
||||
if (!double.TryParse(_renderFpsInput?.Value, out var renderFps) || renderFps <= 0)
|
||||
{
|
||||
ShowValidationError("Render FPS must be a positive number.");
|
||||
return;
|
||||
}
|
||||
config.RenderFPS = renderFps;
|
||||
|
||||
// Validate VideoFPS
|
||||
if (!double.TryParse(_videoFpsInput?.Value, out var videoFps) || videoFps <= 0)
|
||||
{
|
||||
ShowValidationError("Video FPS must be a positive number.");
|
||||
return;
|
||||
}
|
||||
config.VideoFPS = videoFps;
|
||||
|
||||
// Validate RenderWidth
|
||||
if (!int.TryParse(_renderWidthInput?.Value, out var renderWidth) || renderWidth <= 0)
|
||||
{
|
||||
ShowValidationError("Render Width must be an integer greater than 0.");
|
||||
return;
|
||||
}
|
||||
config.RenderWidth = renderWidth;
|
||||
|
||||
// Validate RenderHeight
|
||||
if (!int.TryParse(_renderHeightInput?.Value, out var renderHeight) || renderHeight <= 0)
|
||||
{
|
||||
ShowValidationError("Render Height must be an integer greater than 0.");
|
||||
return;
|
||||
}
|
||||
config.RenderHeight = renderHeight;
|
||||
|
||||
// Validate DelayAfterEnd
|
||||
if (!double.TryParse(_delayAfterEndInput?.Value, out var delay) || delay < 0)
|
||||
{
|
||||
ShowValidationError("Delay After End must be a non-negative number.");
|
||||
return;
|
||||
}
|
||||
config.DelayAfterEnd = delay;
|
||||
|
||||
// Sync Video Config
|
||||
if (_bitrateInput != null && int.TryParse(_bitrateInput.Value, out var bitrate) && bitrate > 0)
|
||||
{
|
||||
@@ -482,16 +528,6 @@ internal static class RenderConfigWindow
|
||||
{
|
||||
config.VideoConfig.QP = qp;
|
||||
}
|
||||
if (_keyframeIntervalInput != null && double.TryParse(_keyframeIntervalInput.Value, out var kf) && kf > 0)
|
||||
{
|
||||
config.VideoConfig.KeyframeInterval = kf;
|
||||
}
|
||||
|
||||
// Sync Audio Config
|
||||
if (_audioBitrateInput != null && int.TryParse(_audioBitrateInput.Value, out var ab) && ab > 0)
|
||||
{
|
||||
config.AudioConfig.AudioBitrate = ab * 1000;
|
||||
}
|
||||
|
||||
// Sync Advanced Config
|
||||
if (_randomSeedInput != null)
|
||||
@@ -573,6 +609,7 @@ internal static class RenderConfigWindow
|
||||
hLayout.childForceExpandWidth = true;
|
||||
hLayout.childForceExpandHeight = false;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
var panelLE = panelObj.AddComponent<LayoutElement>();
|
||||
panelLE.flexibleWidth = 1f;
|
||||
|
||||
@@ -596,6 +633,7 @@ internal static class RenderConfigWindow
|
||||
colLayout.childForceExpandWidth = true;
|
||||
colLayout.childForceExpandHeight = false;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
// 핵심: 좌/우 선호 너비를 0으로 강제해 항상 정확히 절반씩 나누도록 한다.
|
||||
// (기존 행마다 HLG 방식은 라벨/값 텍스트 길이에 따라 preferred가 달라져
|
||||
// 중앙이 (W + P1 - P2) / 2 로 행마다 틀어졌음)
|
||||
@@ -621,6 +659,7 @@ internal static class RenderConfigWindow
|
||||
slotLayout.childForceExpandWidth = true;
|
||||
slotLayout.childForceExpandHeight = false;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
var slotLE = slotObj.AddComponent<LayoutElement>();
|
||||
slotLE.flexibleWidth = 1f;
|
||||
|
||||
@@ -712,16 +751,20 @@ internal static class RenderConfigWindow
|
||||
bool value,
|
||||
string toggleText,
|
||||
string id,
|
||||
Action<bool>? onChanged = null)
|
||||
Action<bool>? onChanged = null,
|
||||
bool generateLabel = true)
|
||||
{
|
||||
var label = O5Factory.ControlText(ctx, colParent, 13f, noPad: true);
|
||||
label.text = labelText;
|
||||
label.color = ctx.Theme.TextDim;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
var labelLE = label.gameObject.AddComponent<LayoutElement>();
|
||||
labelLE.preferredHeight = 18f;
|
||||
labelLE.minHeight = 18f;
|
||||
if (generateLabel)
|
||||
{
|
||||
var label = O5Factory.ControlText(ctx, colParent, 13f, noPad: true);
|
||||
label.text = labelText;
|
||||
label.color = ctx.Theme.TextDim;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
var labelLE = label.gameObject.AddComponent<LayoutElement>();
|
||||
labelLE.preferredHeight = 18f;
|
||||
labelLE.minHeight = 18f;
|
||||
}
|
||||
|
||||
return O5Factory.Toggle(
|
||||
ctx: ctx,
|
||||
@@ -756,12 +799,11 @@ internal static class RenderConfigWindow
|
||||
|
||||
var ddContainer = new GameObject($"DD_{id}");
|
||||
ddContainer.transform.SetParent(colParent, false);
|
||||
var ddRect = ddContainer.AddComponent<RectTransform>();
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
var ddLE = ddContainer.AddComponent<LayoutElement>();
|
||||
ddLE.preferredHeight = 50f;
|
||||
ddLE.minHeight = 50f;
|
||||
ddLE.minHeight = 0f;
|
||||
|
||||
return O5Factory.DropDown(
|
||||
ctx: ctx,
|
||||
|
||||
+21
-1
@@ -1,4 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using FFmpeg.AutoGen;
|
||||
|
||||
namespace ADOFAIRenderer.Util.FFmpeg
|
||||
{
|
||||
@@ -7,4 +9,22 @@ namespace ADOFAIRenderer.Util.FFmpeg
|
||||
{
|
||||
H264, H265, VP9, AV1, VVC
|
||||
}
|
||||
|
||||
internal static class CodecUtil
|
||||
{
|
||||
public static readonly Dictionary<Codec, AVCodecID> AudioCodecMatch = new()
|
||||
{
|
||||
[Codec.H264] = AVCodecID.AV_CODEC_ID_AAC,
|
||||
[Codec.H265] = AVCodecID.AV_CODEC_ID_AAC,
|
||||
[Codec.VP9] = AVCodecID.AV_CODEC_ID_OPUS,
|
||||
[Codec.AV1] = AVCodecID.AV_CODEC_ID_OPUS,
|
||||
[Codec.VVC] = AVCodecID.AV_CODEC_ID_OPUS
|
||||
};
|
||||
|
||||
public static readonly Dictionary<AVCodecID, List<int>> AvailableSampleRate = new()
|
||||
{
|
||||
[AVCodecID.AV_CODEC_ID_AAC] = new List<int> { 44100, 48000, 96000 },
|
||||
[AVCodecID.AV_CODEC_ID_OPUS] = new List<int> { 48000 }
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1536,9 +1536,9 @@ namespace ADOFAIRenderer.Util.FFmpeg
|
||||
if (_pAudioCodecContext == null)
|
||||
throw new Exception("Failed to allocate audio codec context.");
|
||||
|
||||
var sampleRate = audioSettings.SampleRate > 0 ? audioSettings.SampleRate : 44100;
|
||||
var sampleRate = audioSettings.SampleRate > 0 ? audioSettings.SampleRate : 48000;
|
||||
var channels = audioSettings.Channels > 0 ? audioSettings.Channels : 2;
|
||||
var bitrate = audioSettings.Bitrate > 0 ? audioSettings.Bitrate : 128000;
|
||||
var bitrate = audioSettings.Bitrate > 0 ? audioSettings.Bitrate : 256000;
|
||||
|
||||
// Select the first sample format supported by the encoder.
|
||||
// Most encoders prefer AV_SAMPLE_FMT_FLTP (float planar).
|
||||
|
||||
+520
-66
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MelonLoader;
|
||||
@@ -10,95 +11,505 @@ namespace ADOFAIRenderer.Util;
|
||||
|
||||
internal static class FolderDialogUtil
|
||||
{
|
||||
private static int _isDialogOpen;
|
||||
|
||||
public static void OpenFolderBrowser(string initialDirectory, Action<string?> onSelected)
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref _isDialogOpen, 1, 0) != 0)
|
||||
{
|
||||
MelonLogger.Msg("[FolderDialogUtil] Folder dialog is already open.");
|
||||
return;
|
||||
}
|
||||
|
||||
var syncContext = SynchronizationContext.Current;
|
||||
|
||||
Task.Run(() =>
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
string? selected = null;
|
||||
try
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
selected = OpenWindowsFolderBrowser(initialDirectory);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
selected = OpenMacFolderBrowser(initialDirectory);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
selected = OpenLinuxFolderBrowser(initialDirectory);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MelonLogger.Warning($"[FolderDialogUtil] Failed to open folder browser: {ex.Message}");
|
||||
}
|
||||
var ownerHandle = GetGameWindowHandle();
|
||||
|
||||
if (syncContext != null)
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
syncContext.Post(_ => onSelected(selected), null);
|
||||
}
|
||||
else
|
||||
string? selected = null;
|
||||
int oleHr = -1;
|
||||
try
|
||||
{
|
||||
oleHr = OleInitialize(IntPtr.Zero);
|
||||
selected = OpenWindowsFolderBrowser(initialDirectory, ownerHandle);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MelonLogger.Warning($"[FolderDialogUtil] Windows folder dialog error: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (oleHr >= 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
OleUninitialize();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore uninitialize error
|
||||
}
|
||||
}
|
||||
Interlocked.Exchange(ref _isDialogOpen, 0);
|
||||
}
|
||||
|
||||
DispatchResult(syncContext, onSelected, selected);
|
||||
})
|
||||
{
|
||||
IsBackground = true,
|
||||
Name = "FolderDialog-Win"
|
||||
};
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
string? selected = null;
|
||||
try
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
selected = OpenMacFolderBrowser(initialDirectory);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
selected = OpenLinuxFolderBrowser(initialDirectory);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MelonLogger.Warning($"[FolderDialogUtil] Failed to open folder browser: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Interlocked.Exchange(ref _isDialogOpen, 0);
|
||||
}
|
||||
|
||||
DispatchResult(syncContext, onSelected, selected);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void DispatchResult(SynchronizationContext? syncContext, Action<string?> onSelected, string? selected)
|
||||
{
|
||||
if (syncContext != null)
|
||||
{
|
||||
syncContext.Post(_ =>
|
||||
{
|
||||
try
|
||||
{
|
||||
onSelected(selected);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MelonLogger.Warning($"[FolderDialogUtil] Error in folder selected callback: {ex.Message}");
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
onSelected(selected);
|
||||
}
|
||||
});
|
||||
catch (Exception ex)
|
||||
{
|
||||
MelonLogger.Warning($"[FolderDialogUtil] Error in folder selected callback: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string? OpenWindowsFolderBrowser(string initialDirectory)
|
||||
#region Windows Implementation
|
||||
|
||||
private static readonly Guid CLSID_FileOpenDialog = new("DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7");
|
||||
private static readonly Guid IID_IFileOpenDialog = new("d57c7288-d4ad-4768-be02-9d969532d960");
|
||||
private static readonly Guid IID_IShellItem = new("43826D1E-E718-42EE-BC55-A1E261C37BFE");
|
||||
private const int ERROR_CANCELLED_HR = unchecked((int)0x800704C7);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr GetActiveWindow();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr GetForegroundWindow();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
||||
|
||||
private static IntPtr GetGameWindowHandle()
|
||||
{
|
||||
try
|
||||
{
|
||||
var escapedDir = initialDirectory.Replace("'", "''");
|
||||
var script = $@"
|
||||
[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null
|
||||
$f = New-Object System.Windows.Forms.FolderBrowserDialog
|
||||
$f.Description = 'Select Output Directory'
|
||||
if ([System.IO.Directory]::Exists('{escapedDir}')) {{
|
||||
$f.SelectedPath = '{escapedDir}'
|
||||
}}
|
||||
$f.ShowNewFolderButton = $true
|
||||
if ($f.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {{
|
||||
[Console]::Write($f.SelectedPath)
|
||||
}}";
|
||||
var active = GetActiveWindow();
|
||||
if (active != IntPtr.Zero) return active;
|
||||
|
||||
var bytes = System.Text.Encoding.Unicode.GetBytes(script);
|
||||
var base64 = Convert.ToBase64String(bytes);
|
||||
|
||||
var startInfo = new ProcessStartInfo
|
||||
var currentPid = (uint)Process.GetCurrentProcess().Id;
|
||||
var fg = GetForegroundWindow();
|
||||
if (fg != IntPtr.Zero)
|
||||
{
|
||||
FileName = "powershell.exe",
|
||||
Arguments = $"-NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand {base64}",
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
WindowStyle = ProcessWindowStyle.Hidden
|
||||
};
|
||||
GetWindowThreadProcessId(fg, out var fgPid);
|
||||
if (fgPid == currentPid)
|
||||
{
|
||||
return fg;
|
||||
}
|
||||
}
|
||||
|
||||
using var process = Process.Start(startInfo);
|
||||
if (process == null) return null;
|
||||
var mainHandle = Process.GetCurrentProcess().MainWindowHandle;
|
||||
if (mainHandle != IntPtr.Zero)
|
||||
{
|
||||
return mainHandle;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore failure to detect window handle
|
||||
}
|
||||
|
||||
var output = process.StandardOutput.ReadToEnd().Trim();
|
||||
process.WaitForExit();
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
return !string.IsNullOrEmpty(output) && Directory.Exists(output) ? output : null;
|
||||
private static string? OpenWindowsFolderBrowser(string initialDirectory, IntPtr ownerHandle)
|
||||
{
|
||||
try
|
||||
{
|
||||
return OpenWindowsFolderBrowserModern(initialDirectory, ownerHandle);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MelonLogger.Warning($"[FolderDialogUtil] Windows folder dialog error: {ex.Message}");
|
||||
return null;
|
||||
MelonLogger.Warning($"[FolderDialogUtil] Modern folder dialog failed ({ex.Message}), falling back to legacy dialog.");
|
||||
return OpenWindowsFolderBrowserLegacy(initialDirectory, ownerHandle);
|
||||
}
|
||||
}
|
||||
|
||||
private static string? OpenWindowsFolderBrowserModern(string initialDirectory, IntPtr ownerHandle)
|
||||
{
|
||||
IFileOpenDialog? dialog = null;
|
||||
|
||||
// 1. Try native CoCreateInstance first (works on Mono and .NET without class registration)
|
||||
var clsid = CLSID_FileOpenDialog;
|
||||
var iid = IID_IFileOpenDialog;
|
||||
int createHr = CoCreateInstance(ref clsid, IntPtr.Zero, 1 /* CLSCTX_INPROC_SERVER */, ref iid, out dialog);
|
||||
|
||||
if (createHr != 0 || dialog == null)
|
||||
{
|
||||
// 2. Fallback to Activator via Type.GetTypeFromCLSID
|
||||
var comType = Type.GetTypeFromCLSID(CLSID_FileOpenDialog);
|
||||
if (comType != null)
|
||||
{
|
||||
var instance = Activator.CreateInstance(comType);
|
||||
dialog = instance as IFileOpenDialog;
|
||||
}
|
||||
}
|
||||
|
||||
if (dialog == null)
|
||||
{
|
||||
throw new COMException("Failed to instantiate IFileOpenDialog via COM.", createHr);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
dialog.SetOptions(FOS.FOS_PICKFOLDERS | FOS.FOS_FORCEFILESYSTEM | FOS.FOS_PATHMUSTEXIST);
|
||||
dialog.SetTitle("Select Output Directory");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(initialDirectory))
|
||||
{
|
||||
try
|
||||
{
|
||||
var normalized = Path.GetFullPath(initialDirectory).TrimEnd('\\', '/');
|
||||
if (Directory.Exists(normalized))
|
||||
{
|
||||
var shellItemGuid = IID_IShellItem;
|
||||
int itemHr = SHCreateItemFromParsingName(normalized, IntPtr.Zero, ref shellItemGuid, out var initialItem);
|
||||
if (itemHr == 0 && initialItem != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
dialog.SetFolder(initialItem);
|
||||
dialog.SetDefaultFolder(initialItem);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.ReleaseComObject(initialItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore failure to set initial folder
|
||||
}
|
||||
}
|
||||
|
||||
int hr = dialog.Show(ownerHandle);
|
||||
if (hr != 0 && hr != ERROR_CANCELLED_HR && ownerHandle != IntPtr.Zero)
|
||||
{
|
||||
// If Show failed with ownerHandle (e.g. cross-thread or invalid handle), retry without owner
|
||||
MelonLogger.Msg($"[FolderDialogUtil] dialog.Show(ownerHandle) returned 0x{hr:X8}, retrying with IntPtr.Zero.");
|
||||
hr = dialog.Show(IntPtr.Zero);
|
||||
}
|
||||
|
||||
if (hr == ERROR_CANCELLED_HR)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (hr != 0)
|
||||
{
|
||||
throw new COMException("IFileOpenDialog.Show failed", hr);
|
||||
}
|
||||
|
||||
dialog.GetResult(out var resultItem);
|
||||
if (resultItem == null) return null;
|
||||
|
||||
try
|
||||
{
|
||||
if (resultItem.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out var pszPath) == 0 && pszPath != IntPtr.Zero)
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = Marshal.PtrToStringUni(pszPath);
|
||||
return !string.IsNullOrEmpty(path) && Directory.Exists(path) ? path : null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pszPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.ReleaseComObject(resultItem);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.ReleaseComObject(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
private static string? OpenWindowsFolderBrowserLegacy(string initialDirectory, IntPtr ownerHandle)
|
||||
{
|
||||
IntPtr pszDisplayName = Marshal.AllocHGlobal(260 * sizeof(char));
|
||||
IntPtr initialDirPtr = IntPtr.Zero;
|
||||
BrowseCallbackProc? callback = null;
|
||||
IntPtr pidl = IntPtr.Zero;
|
||||
|
||||
try
|
||||
{
|
||||
var bi = new BROWSEINFO
|
||||
{
|
||||
hwndOwner = ownerHandle,
|
||||
pidlRoot = IntPtr.Zero,
|
||||
pszDisplayName = pszDisplayName,
|
||||
lpszTitle = "Select Output Directory",
|
||||
ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | BIF_EDITBOX
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(initialDirectory))
|
||||
{
|
||||
try
|
||||
{
|
||||
var normalized = Path.GetFullPath(initialDirectory).TrimEnd('\\', '/');
|
||||
if (Directory.Exists(normalized))
|
||||
{
|
||||
initialDirPtr = Marshal.StringToHGlobalUni(normalized);
|
||||
callback = (hwnd, uMsg, lParam, lpData) =>
|
||||
{
|
||||
if (uMsg == BFFM_INITIALIZED && lpData != IntPtr.Zero)
|
||||
{
|
||||
SendMessage(hwnd, BFFM_SETSELECTIONW, (IntPtr)1, lpData);
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
bi.lpfn = callback;
|
||||
bi.lParam = initialDirPtr;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore failure to prepare initial directory
|
||||
}
|
||||
}
|
||||
|
||||
pidl = SHBrowseForFolderW(ref bi);
|
||||
if (pidl == IntPtr.Zero && ownerHandle != IntPtr.Zero)
|
||||
{
|
||||
// If it returned null with ownerHandle, check if retry with IntPtr.Zero is appropriate
|
||||
// But note: cancelling also returns Zero. We do not redundantly re-prompt if cancelled.
|
||||
}
|
||||
|
||||
if (pidl != IntPtr.Zero)
|
||||
{
|
||||
var sb = new StringBuilder(260);
|
||||
if (SHGetPathFromIDListW(pidl, sb))
|
||||
{
|
||||
var path = sb.ToString();
|
||||
return !string.IsNullOrEmpty(path) && Directory.Exists(path) ? path : null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (pidl != IntPtr.Zero)
|
||||
{
|
||||
Marshal.FreeCoTaskMem(pidl);
|
||||
}
|
||||
if (initialDirPtr != IntPtr.Zero)
|
||||
{
|
||||
Marshal.FreeHGlobal(initialDirPtr);
|
||||
}
|
||||
if (pszDisplayName != IntPtr.Zero)
|
||||
{
|
||||
Marshal.FreeHGlobal(pszDisplayName);
|
||||
}
|
||||
GC.KeepAlive(callback);
|
||||
}
|
||||
}
|
||||
|
||||
#region COM & Win32 Interop Definitions
|
||||
|
||||
[Flags]
|
||||
private enum FOS : uint
|
||||
{
|
||||
FOS_NOCHANGEDIR = 0x00000008,
|
||||
FOS_PICKFOLDERS = 0x00000020,
|
||||
FOS_FORCEFILESYSTEM = 0x00000040,
|
||||
FOS_PATHMUSTEXIST = 0x00000800,
|
||||
FOS_FILEMUSTEXIST = 0x00001000,
|
||||
}
|
||||
|
||||
private enum SIGDN : uint
|
||||
{
|
||||
SIGDN_FILESYSPATH = 0x80058000
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IShellItem
|
||||
{
|
||||
void BindToHandler(IntPtr pbc, [In] ref Guid bhid, [In] ref Guid riid, out IntPtr ppv);
|
||||
void GetParent(out IShellItem ppsi);
|
||||
[PreserveSig]
|
||||
int GetDisplayName(SIGDN sigdnName, out IntPtr ppszName);
|
||||
void GetAttributes(uint sfgaoMask, out uint psfgaoAttribs);
|
||||
void Compare(IShellItem psi, uint hint, out int piOrder);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("d57c7288-d4ad-4768-be02-9d969532d960")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IFileOpenDialog
|
||||
{
|
||||
[PreserveSig]
|
||||
int Show(IntPtr parent);
|
||||
void SetFileTypes(uint cFileTypes, IntPtr rgFilterSpec);
|
||||
void SetFileTypeIndex(uint iFileType);
|
||||
void GetFileTypeIndex(out uint piFileType);
|
||||
void Advise(IntPtr pfde, out uint pdwCookie);
|
||||
void Unadvise(uint dwCookie);
|
||||
void SetOptions(FOS fos);
|
||||
void GetOptions(out FOS pfos);
|
||||
void SetDefaultFolder(IShellItem psi);
|
||||
void SetFolder(IShellItem psi);
|
||||
void GetFolder(out IShellItem ppsi);
|
||||
void GetCurrentSelection(out IShellItem ppsi);
|
||||
void SetFileName([MarshalAs(UnmanagedType.LPWStr)] string pszName);
|
||||
void GetFileName([MarshalAs(UnmanagedType.LPWStr)] out string pszName);
|
||||
void SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pszTitle);
|
||||
void SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr)] string pszText);
|
||||
void SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr)] string pszLabel);
|
||||
void GetResult(out IShellItem ppsi);
|
||||
void AddPlace(IShellItem psi, int fdap);
|
||||
void SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension);
|
||||
void Close(int hr);
|
||||
void SetClientGuid(ref Guid guid);
|
||||
void ClearClientData();
|
||||
void SetFilter(IntPtr pFilter);
|
||||
void GetResults(out IntPtr ppenum);
|
||||
void GetSelectedItems(out IntPtr ppsai);
|
||||
}
|
||||
|
||||
[DllImport("ole32.dll", ExactSpelling = true)]
|
||||
private static extern int OleInitialize(IntPtr pvReserved);
|
||||
|
||||
[DllImport("ole32.dll", ExactSpelling = true)]
|
||||
private static extern void OleUninitialize();
|
||||
|
||||
[DllImport("ole32.dll", ExactSpelling = true)]
|
||||
private static extern int CoCreateInstance(
|
||||
[In] ref Guid rclsid,
|
||||
IntPtr pUnkOuter,
|
||||
uint dwClsContext,
|
||||
[In] ref Guid riid,
|
||||
[Out, MarshalAs(UnmanagedType.Interface)] out IFileOpenDialog ppv);
|
||||
|
||||
[DllImport("shell32.dll", CharSet = CharSet.Unicode, PreserveSig = true)]
|
||||
private static extern int SHCreateItemFromParsingName(
|
||||
[MarshalAs(UnmanagedType.LPWStr)] string pszPath,
|
||||
IntPtr pbc,
|
||||
[In] ref Guid riid,
|
||||
[Out, MarshalAs(UnmanagedType.Interface)] out IShellItem ppv);
|
||||
|
||||
private const uint BIF_RETURNONLYFSDIRS = 0x0001;
|
||||
private const uint BIF_NEWDIALOGSTYLE = 0x0040;
|
||||
private const uint BIF_EDITBOX = 0x0010;
|
||||
private const uint BFFM_INITIALIZED = 1;
|
||||
private const uint BFFM_SETSELECTIONW = 0x0400 + 103;
|
||||
|
||||
private delegate int BrowseCallbackProc(IntPtr hwnd, uint uMsg, IntPtr lParam, IntPtr lpData);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
private struct BROWSEINFO
|
||||
{
|
||||
public IntPtr hwndOwner;
|
||||
public IntPtr pidlRoot;
|
||||
public IntPtr pszDisplayName;
|
||||
public string lpszTitle;
|
||||
public uint ulFlags;
|
||||
public BrowseCallbackProc? lpfn;
|
||||
public IntPtr lParam;
|
||||
public int iImage;
|
||||
}
|
||||
|
||||
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern IntPtr SHBrowseForFolderW(ref BROWSEINFO lpbi);
|
||||
|
||||
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool SHGetPathFromIDListW(IntPtr pidl, StringBuilder pszPath);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region macOS Implementation
|
||||
|
||||
private static string? OpenMacFolderBrowser(string initialDirectory)
|
||||
{
|
||||
try
|
||||
{
|
||||
var escaped = initialDirectory.Replace("\"", "\\\"");
|
||||
var script = $"POSIX path of (choose folder with prompt \"Select Output Directory\" default location \"{escaped}\")";
|
||||
string script;
|
||||
if (!string.IsNullOrEmpty(initialDirectory) && Directory.Exists(initialDirectory))
|
||||
{
|
||||
var escaped = initialDirectory.Replace("\\", "\\\\").Replace("\"", "\\\"");
|
||||
script = $"POSIX path of (choose folder with prompt \"Select Output Directory\" default location (POSIX file \"{escaped}\"))";
|
||||
}
|
||||
else
|
||||
{
|
||||
script = "POSIX path of (choose folder with prompt \"Select Output Directory\")";
|
||||
}
|
||||
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
@@ -119,12 +530,17 @@ if ($f.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {{
|
||||
|
||||
return !string.IsNullOrEmpty(output) && Directory.Exists(output) ? output : null;
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
MelonLogger.Warning($"[FolderDialogUtil] Mac folder dialog error: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Linux Implementation
|
||||
|
||||
private static string? OpenLinuxFolderBrowser(string initialDirectory)
|
||||
{
|
||||
try
|
||||
@@ -145,17 +561,55 @@ if ($f.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {{
|
||||
startInfo.ArgumentList.Add($"--filename={initialDirectory}");
|
||||
}
|
||||
|
||||
using var process = Process.Start(startInfo);
|
||||
if (process == null) return null;
|
||||
try
|
||||
{
|
||||
using var process = Process.Start(startInfo);
|
||||
if (process != null)
|
||||
{
|
||||
var output = process.StandardOutput.ReadToEnd().Trim();
|
||||
process.WaitForExit();
|
||||
|
||||
var output = process.StandardOutput.ReadToEnd().Trim();
|
||||
process.WaitForExit();
|
||||
if (process.ExitCode == 0 && !string.IsNullOrEmpty(output) && Directory.Exists(output))
|
||||
{
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fallback to kdialog if zenity fails to start
|
||||
}
|
||||
|
||||
return !string.IsNullOrEmpty(output) && Directory.Exists(output) ? output : null;
|
||||
var kdialogInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "kdialog",
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
WindowStyle = ProcessWindowStyle.Hidden
|
||||
};
|
||||
kdialogInfo.ArgumentList.Add("--getexistingdirectory");
|
||||
if (!string.IsNullOrEmpty(initialDirectory) && Directory.Exists(initialDirectory))
|
||||
{
|
||||
kdialogInfo.ArgumentList.Add(initialDirectory);
|
||||
}
|
||||
kdialogInfo.ArgumentList.Add("--title");
|
||||
kdialogInfo.ArgumentList.Add("Select Output Directory");
|
||||
|
||||
using var kdialogProcess = Process.Start(kdialogInfo);
|
||||
if (kdialogProcess == null) return null;
|
||||
|
||||
var koutput = kdialogProcess.StandardOutput.ReadToEnd().Trim();
|
||||
kdialogProcess.WaitForExit();
|
||||
|
||||
return !string.IsNullOrEmpty(koutput) && Directory.Exists(koutput) ? koutput : null;
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
MelonLogger.Warning($"[FolderDialogUtil] Linux folder dialog error: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -63,6 +63,7 @@ namespace ADOFAIRenderer.Util
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static string[]? GetHKLMSubKeyNames(string parentKeyPath)
|
||||
{
|
||||
if (RegistryKeyType == null || OpenBaseKeyMethod == null || OpenSubKeyMethod == null || GetSubKeyNamesMethod == null)
|
||||
@@ -94,6 +95,7 @@ namespace ADOFAIRenderer.Util
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static string? GetHKLMValue(string keyPath, string valueName)
|
||||
{
|
||||
if (RegistryKeyType == null || OpenBaseKeyMethod == null || OpenSubKeyMethod == null || GetValueMethod == null)
|
||||
|
||||
Reference in new issue
Block a user