Skip to content

Commit

Permalink
调整PR代码,全面支持三种模式的环境设置
Browse files Browse the repository at this point in the history
  • Loading branch information
YohoYang committed Apr 10, 2024
1 parent 5636951 commit e801190
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 311 deletions.
22 changes: 2 additions & 20 deletions VSGUI/API/CommonApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ public static void DeleteEmptyDirectories(string startLocation)
}

/// <summary>
/// 检查注册表,看是否已绑定vseditor
/// 检查注册表,看是否已绑定内建的vseditor。 返回2为已绑定
/// </summary>
/// <returns></returns>
public static int CheckVSEditorInstall()
public static int CheckBuildinVSEditorInstall()
{
int count = 0;
try
Expand Down Expand Up @@ -316,23 +316,5 @@ public static string GetAppTempPath()
return pstr;
}

public static bool CheckCustomPyenvExec()
{
return File.Exists(IniApi.IniReadValue("pythonEnvPathBox"));
}

public static string GetCustomPyenvDir()
{
if (CheckCustomPyenvExec())
{
return System.IO.Path.GetDirectoryName(IniApi.IniReadValue("pythonEnvPathBox"));

}
else
{
return "";
}
}

}
}
78 changes: 78 additions & 0 deletions VSGUI/API/EnvApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace VSGUI.API
{
internal class EnvApi
{
public static string[] getEnvVersion(string path)
{
string[] versions = new string[2];
if (path == null)
{
path = "";
}
else
{
if (!path.EndsWith(@"\"))
{
path = path + @"\";
}
}
MatchCollection x;
try
{
string PyVer = ProcessApi.RunSyncProcess(path, @"python.exe --version");
string VsVer = ProcessApi.RunSyncProcess(path, @"vspipe.exe --version");

x = Regex.Matches(PyVer, @"Python (.*)\s");
if (x.Count > 0)
{
versions[0] = x[0].Groups[1].Value.Replace("\r\n","").Replace("\r", "").Replace("\n", "");
}

x = Regex.Matches(VsVer, @"VapourSynth(?:.|\s)*?Core (.*)\s");
if (x.Count > 0)
{
versions[1] = x[0].Groups[1].Value.Replace("\r\n", "").Replace("\r", "").Replace("\n", "");
}
}
catch (Exception)
{

}
return versions;
}

public static bool checkEnvEditorNow()
{
string envpath = MainWindow.envpath;
if (envpath == "")//系统环境
{
//坏了,系统的editor怎么找呢,这种情况下应该是直接安装editor了
return false;
}
else
{
if (!envpath.EndsWith(@"\"))
{
envpath += @"\";
}
if (File.Exists(envpath + @"vsedit.exe"))
{
return true;
}
else
{
return false;
}
}
}
}
}
42 changes: 4 additions & 38 deletions VSGUI/API/QueueApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,8 @@ public static string ProcessCommandStr(int queueid, string type, int encoderid,
//根据类型处理参数
if (type == "video")
{
string EmbedVSPipe = MainWindow.binpath + @"\vs\";
string customVSPipe = CommonApi.GetCustomPyenvDir();

if (CommonApi.CheckCustomPyenvExec() && Convert.ToBoolean(IniApi.IniReadValue("UseSystemEnvironment")))
{
clipath = customVSPipe;
}
else
{
clipath = EmbedVSPipe;
}

//clipath = MainWindow.binpath + @"\vs\";
clipath = "";//video可不存这个参数,都按实时的设置来
pipecommon = @"VSPipe.exe" + " -c y4m ";
pipeconnect = " - | ";
}
Expand Down Expand Up @@ -464,18 +453,6 @@ public static void UpdateTotalframes(string queueid)
if (GetQueueListitem(queueid, "type") == "video")
{
string vpypath;
string EmbedVSPipe = MainWindow.binpath + @"\vs\";
string customVSPipe = CommonApi.GetCustomPyenvDir();
string VSPExec;

if (CommonApi.CheckCustomPyenvExec() && Convert.ToBoolean(IniApi.IniReadValue("UseSystemEnvironment")))
{
VSPExec = customVSPipe;
}
else
{
VSPExec = EmbedVSPipe;
}

if (Path.GetExtension(GetQueueListitem(queueid, "input")) == ".vpy")
{
Expand All @@ -485,7 +462,8 @@ public static void UpdateTotalframes(string queueid)
{
vpypath = GetQueueListitem(queueid, "scriptfilepath");
}
string result = ProcessApi.RunSyncProcess(VSPExec, "VSPipe.exe" + " --info " + "\"" + vpypath + "\"");

string result = ProcessApi.RunSyncProcess(MainWindow.envpath, "VSPipe.exe" + " --info " + "\"" + vpypath + "\"");
if (result != null)
{
var x = Regex.Matches(result, @"Frames: (\d+)|(\d+.\d+) fps");
Expand Down Expand Up @@ -823,19 +801,7 @@ public static void VpyFileInputCheck(string videoinputboxText, out string cuttex
string inputsuffix = Path.GetExtension(inputpath).ToLower();
if (inputsuffix == ".vpy")
{
string EmbedVSPipe = MainWindow.binpath + @"\vs\";
string customVSPipe = CommonApi.GetCustomPyenvDir();
string VSPExec;

if (CommonApi.CheckCustomPyenvExec() && Convert.ToBoolean(IniApi.IniReadValue("UseSystemEnvironment")))
{
VSPExec = customVSPipe;
}
else
{
VSPExec = EmbedVSPipe;
}
string result = ProcessApi.RunSyncProcess(VSPExec, @"VSPipe.exe" + " --info " + "\"" + inputpath + "\"");
string result = ProcessApi.RunSyncProcess(MainWindow.envpath, @"VSPipe.exe" + " --info " + "\"" + inputpath + "\"");

if (result != null)
{
Expand Down
71 changes: 0 additions & 71 deletions VSGUI/API/VersionApi.cs

This file was deleted.

17 changes: 3 additions & 14 deletions VSGUI/API/VideoApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,17 @@ public static void PreviewTempVpy(string script)

public static void OpenPreviewWindows(string vpyPath)
{
string EmbedVSPExec = MainWindow.binpath + @"\vs\vsedit-previewer.exe";
string customVSPExec = CommonApi.GetCustomPyenvDir() + @"\vsedit-previewer.exe";
string VSPExec;
if (CommonApi.CheckCustomPyenvExec() && Convert.ToBoolean(IniApi.IniReadValue("UseSystemEnvironment")))
{
VSPExec = customVSPExec;
}
else
{
VSPExec = EmbedVSPExec;
}

string previewPath = MainWindow.envpath + @"\vsedit-previewer.exe";
Process proc = new Process
{
StartInfo = new ProcessStartInfo(VSPExec)
StartInfo = new ProcessStartInfo(previewPath)
{
CreateNoWindow = true,
UseShellExecute = false,
Arguments = "\"" + vpyPath + "\"",
}
};
if (File.Exists(VSPExec))
if (File.Exists(previewPath))
{
proc.Start();
}
Expand Down
96 changes: 55 additions & 41 deletions VSGUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -651,47 +651,61 @@
<CheckBox x:Name="EnableQueueLog" Content="{DynamicResource enableQueueLog}" Checked="ConfigCheckBox_Checked" Unchecked="ConfigCheckBox_Checked"></CheckBox>
<TextBlock Text="{DynamicResource enableQueueLogDesc}" Margin="23,0,0,0" TextWrapping="Wrap"/>
<hc:Divider Margin="0"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<CheckBox x:Name="CustomPyenv" Content="{DynamicResource enableCustomPyenv}" Checked="ConfigCheckBox_Checked" Unchecked="ConfigCheckBox_Checked"></CheckBox>
<TextBlock x:Name="CustomPyenvDesc" Grid.Column="1" Text=""/>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="selectPythonEnvPathbox" Grid.Column="0" PreviewDragOver="TextBox_PreviewDragOver" PreviewDrop="TextBox_PreviewDrop"/>
<Button x:Name="selectPythonEnvPath" Grid.Column="2" Content="..." Margin="4,0,0,0" Click="SelectPythonEnvPath_Click"/>
</Grid>

<hc:Divider Margin="0"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<CheckBox x:Name="UseSystemEnvironment" Content="{DynamicResource useSystemEnvironment}" Checked="ConfigCheckBox_Checked" Unchecked="ConfigCheckBox_Checked"></CheckBox>
<DockPanel Grid.Column="1" Height="16" VerticalAlignment="Center">
<TextBlock Text="{DynamicResource buildin}" />
<TextBlock Text=":" />
<TextBlock Text="py" Margin="8,0,0,0"/>
<TextBlock x:Name="buildinpyvertext" Text="..." Margin="4,0,0,0" TextDecorations="Underline"/>
<TextBlock Text="vs" Margin="8,0,0,0"/>
<TextBlock x:Name="buildinvsvertext" Text="..." Margin="4,0,0,0" TextDecorations="Underline"/>
<TextBlock Text="{DynamicResource system}" Margin="14,0,0,0"/>
<TextBlock Text=":" />
<TextBlock Text="py" Margin="8,0,0,0"/>
<TextBlock x:Name="systempyvertext" Text="..." Margin="4,0,0,0" TextDecorations="Underline"/>
<TextBlock Text="vs" Margin="8,0,0,0"/>
<TextBlock x:Name="systemvsvertext" Text="..." Margin="4,0,0,0" TextDecorations="Underline"/>
</DockPanel>
</Grid>
<TextBlock Text="{DynamicResource useSystemEnvironmentDesc}" Margin="23,0,0,0" TextWrapping="Wrap"/>

<TextBlock Text="{DynamicResource p040}" TextWrapping="Wrap"/>
<TextBlock Text="{DynamicResource p041}" Margin="23,0,0,0"/>
<StackPanel Margin="23,0,0,0">
<StackPanel>
<Grid Margin="0,0,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<RadioButton x:Name="buildinEnvRadio" GroupName="cenv" Content="{DynamicResource buildin}" HorizontalAlignment="Left" Checked="envRadio_Checked" IsEnabled="False"/>
<DockPanel Grid.Column="1">
<TextBlock Text="python"/>
<TextBlock x:Name="buildinpyvertext" Text="..." Margin="4,0,0,0" TextDecorations="Underline"/>
<TextBlock Text="vapoursynth" Margin="8,0,0,0"/>
<TextBlock x:Name="buildinvsvertext" Text="..." Margin="4,0,0,0" TextDecorations="Underline"/>
</DockPanel>
</Grid>
<Grid Margin="0,0,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<RadioButton x:Name="systemEnvRadio" GroupName="cenv" Content="{DynamicResource system}" HorizontalAlignment="Left" Checked="envRadio_Checked" IsEnabled="False"/>
<DockPanel Grid.Column="1">
<TextBlock Text="python"/>
<TextBlock x:Name="systempyvertext" Text="..." Margin="4,0,0,0" TextDecorations="Underline"/>
<TextBlock Text="vapoursynth" Margin="8,0,0,0"/>
<TextBlock x:Name="systemvsvertext" Text="..." Margin="4,0,0,0" TextDecorations="Underline"/>
</DockPanel>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<RadioButton x:Name="customEnvRadio" GroupName="cenv" Content="自定义" HorizontalAlignment="Left" Checked="envRadio_Checked" IsEnabled="False"/>
<StackPanel Grid.Column="1">
<DockPanel>
<TextBlock Text="python"/>
<TextBlock x:Name="custompyvertext" Text="..." Margin="4,0,0,0" TextDecorations="Underline"/>
<TextBlock Text="vapoursynth" Margin="8,0,0,0"/>
<TextBlock x:Name="customvsvertext" Text="..." Margin="4,0,0,0" TextDecorations="Underline"/>
</DockPanel>
<DockPanel Margin="0,6,0,0">
<TextBlock Text="{DynamicResource p042}"/>
<TextBlock Text=": "/>
<TextBlock x:Name="CustomEnvPathBox" TextWrapping="Wrap"/>
<TextBlock x:Name="CustomEnvPathboxTips" TextWrapping="Wrap" Text="{DynamicResource p043}" Foreground="#FF6F6F6F"/>
</DockPanel>
</StackPanel>
<Button x:Name="selectCustomEnvPath" Grid.Column="2" Content="..." Margin="4,0,0,0" Click="SelectCustomEnvPath_Click"/>
</Grid>
</StackPanel>
</StackPanel>
<hc:Divider Margin="0"/>
</hc:UniformSpacingPanel>
</StackPanel>
Expand Down
Loading

0 comments on commit e801190

Please sign in to comment.