Skip to content

Commit f74403c

Browse files
committed
Add debugging launch and optimize file name generation
Enable on-demand debugger launch in debug mode to facilitate development. Simplify and streamline export file name logic by removing redundant operations and improving clarity.
1 parent 03c4ad6 commit f74403c

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

source/SaveAllFormat/EntryPoint.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System.Diagnostics;
2+
using System.IO;
23
using System.Windows.Forms;
34
using Nikse.SubtitleEdit.Core.Common;
45
using Nikse.SubtitleEdit.Core.SubtitleFormats;
@@ -16,6 +17,12 @@ public class ExportAllFormats : IPlugin
1617

1718
public string DoAction(Form parentForm, string srtText, double frameRate, string uiLineBreak, string file, string videoFile, string rawText)
1819
{
20+
#if DEBUG
21+
if (!Debugger.IsAttached)
22+
{
23+
Debugger.Launch();
24+
}
25+
#endif
1926
// subtitle not loaded
2027
if (string.IsNullOrWhiteSpace(srtText))
2128
{

source/SaveAllFormat/Main.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ await Task.Run(() =>
8181
{
8282
try
8383
{
84-
var outputFileName = Path.Combine(_exportLocation, GetExportFileName(_subtitle.FileName, exportFormat.Name, exportFormat.Extension));
85-
var content = exportFormat.ToText(_subtitle, _subtitle.FileName);
84+
string outputFileName = Path.Combine(_exportLocation, GetExportFileName(_subtitle.FileName, exportFormat.Name, exportFormat.Extension));
85+
string content = exportFormat.ToText(_subtitle, _subtitle.FileName);
8686
File.WriteAllText(outputFileName, content, Encoding.UTF8);
8787
}
8888
catch (Exception ex)
8989
{
9090
Trace.WriteLine(ex.Message);
9191
}
9292
});
93-
SpinWait.SpinUntil(() => parallelLoopResult.IsCompleted);
93+
// SpinWait.SpinUntil(() => parallelLoopResult.IsCompleted);
9494
}).ConfigureAwait(true);
9595

9696
Process.Start("explorer", $"\"{_exportLocation}\"");
@@ -99,21 +99,16 @@ await Task.Run(() =>
9999

100100
private static string GetExportFileName(string file, string formatName, string extension)
101101
{
102-
if (string.IsNullOrWhiteSpace(file))
103-
{
104-
return Path.GetRandomFileName() + extension;
105-
}
102+
string newName = string.IsNullOrWhiteSpace(file)
103+
? Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + "_" + formatName + extension
104+
: $"{Path.GetFileNameWithoutExtension(file)}_{formatName}{extension}";
106105

107-
string fileName = Path.GetFileNameWithoutExtension(file);
108-
string newName = $"{fileName}_{formatName}{extension}";
109-
foreach (var ch in Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars()))
106+
foreach (char ch in Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars()))
110107
{
111108
newName = newName.Replace(ch.ToString(), "_");
112109
}
113110

114-
newName = newName.Replace(" ", "-");
115-
newName = newName.Replace(" ", "-");
116-
return newName;
111+
return newName.Replace(" ", "-");
117112
}
118113
}
119-
}
114+
}

0 commit comments

Comments
 (0)