Skip to content

Commit

Permalink
Code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Sep 5, 2024
1 parent 8343a10 commit 7901a59
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 143 deletions.
2 changes: 1 addition & 1 deletion v2rayN/ServiceLib/Handler/TaskHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private async Task UpdateTaskRunGeo(Config config, Action<bool, string> update)
{
if ((dtNow - autoUpdateGeoTime).Hours % config.guiItem.autoUpdateInterval == 0)
{
updateHandle.UpdateGeoFileAll(config, (bool success, string msg) =>
await updateHandle.UpdateGeoFileAll(config, (bool success, string msg) =>
{
update(false, msg);
});
Expand Down
122 changes: 0 additions & 122 deletions v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ public class MainWindowViewModel : MyReactiveObject
public ReactiveCommand<Unit, Unit> ClearServerStatisticsCmd { get; }
public ReactiveCommand<Unit, Unit> OpenTheFileLocationCmd { get; }

//CheckUpdate
public ReactiveCommand<Unit, Unit> CheckUpdateNCmd { get; }

public ReactiveCommand<Unit, Unit> CheckUpdateXrayCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateClashMetaCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateSingBoxCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateGeoCmd { get; }
public ReactiveCommand<Unit, Unit> ReloadCmd { get; }

[Reactive]
Expand Down Expand Up @@ -295,28 +288,6 @@ public MainWindowViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
Utils.ProcessStart("Explorer", $"/select,{Utils.GetConfigPath()}");
});

//CheckUpdate
CheckUpdateNCmd = ReactiveCommand.Create(() =>
{
CheckUpdateN();
});
CheckUpdateXrayCoreCmd = ReactiveCommand.Create(() =>
{
CheckUpdateCore(ECoreType.Xray, null);
});
CheckUpdateClashMetaCoreCmd = ReactiveCommand.Create(() =>
{
CheckUpdateCore(ECoreType.mihomo, false);
});
CheckUpdateSingBoxCoreCmd = ReactiveCommand.Create(() =>
{
CheckUpdateCore(ECoreType.sing_box, null);
});
CheckUpdateGeoCmd = ReactiveCommand.Create(() =>
{
CheckUpdateGeo();
});

ReloadCmd = ReactiveCommand.Create(() =>
{
Reload();
Expand Down Expand Up @@ -718,99 +689,6 @@ private void RebootAsAdmin()

#endregion Setting

#region CheckUpdate

private void CheckUpdateN()
{
//Check for standalone windows .Net version
if (Utils.IsWindows()
&& File.Exists(Path.Combine(Utils.StartupPath(), "wpfgfx_cor3.dll"))
&& File.Exists(Path.Combine(Utils.StartupPath(), "D3DCompiler_47_cor3.dll"))
)
{
_noticeHandler?.SendMessageAndEnqueue(ResUI.UpdateStandalonePackageTip);
return;
}

void _updateUI(bool success, string msg)
{
_noticeHandler?.SendMessage(msg);
if (success)
{
try
{
var fileName = msg;
Process process = new()
{
StartInfo = new ProcessStartInfo
{
FileName = "v2rayUpgrade",
Arguments = fileName.AppendQuotes(),
WorkingDirectory = Utils.StartupPath()
}
};
process.Start();
if (process.Id > 0)
{
MyAppExitAsync(false);
}
}
catch (Exception ex)
{
_noticeHandler?.SendMessage(ex.Message);
}
}
}
(new UpdateHandler()).CheckUpdateGuiN(_config, _updateUI, _config.guiItem.checkPreReleaseUpdate);
}

private void CheckUpdateCore(ECoreType type, bool? preRelease)
{
void _updateUI(bool success, string msg)
{
_noticeHandler?.SendMessage(msg);
if (success)
{
CloseCore();

string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(msg));
string toPath = Utils.GetBinPath("", type.ToString());

if (fileName.Contains(".tar.gz"))
{
//It's too complicated to unzip. TODO
}
else if (fileName.Contains(".gz"))
{
FileManager.UncompressedFile(fileName, toPath, type.ToString());
}
else
{
FileManager.ZipExtractToFile(fileName, toPath, _config.guiItem.ignoreGeoUpdateCore ? "geo" : "");
}

_noticeHandler?.SendMessage(ResUI.MsgUpdateV2rayCoreSuccessfullyMore);

Reload();

_noticeHandler?.SendMessage(ResUI.MsgUpdateV2rayCoreSuccessfully);

if (File.Exists(fileName))
{
File.Delete(fileName);
}
}
}
(new UpdateHandler()).CheckUpdateCore(type, _config, _updateUI, preRelease ?? _config.guiItem.checkPreReleaseUpdate);
}

private void CheckUpdateGeo()
{
(new UpdateHandler()).UpdateGeoFileAll(_config, UpdateTaskHandler);
}

#endregion CheckUpdate

#region core job

public void Reload()
Expand Down
15 changes: 4 additions & 11 deletions v2rayN/v2rayN/Views/CheckUpdateView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,26 @@
DockPanel.Dock="Bottom"
Orientation="Horizontal">

<TextBlock
Grid.Row="9"
Grid.Column="0"
<TextBlock
Margin="{StaticResource SettingItemMargin}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbSettingsEnableCheckPreReleaseUpdate}" />
<ToggleButton
x:Name="togEnableCheckPreReleaseUpdate"
Grid.Row="9"
Grid.Column="1"
x:Name="togEnableCheckPreReleaseUpdate"
Margin="{StaticResource SettingItemMargin}"
HorizontalAlignment="Left" />

<Button
x:Name="btnCheckUpdate"
Grid.Row="2"
x:Name="btnCheckUpdate"
Width="100"
Margin="8"
Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}"
Content="{x:Static resx:ResUI.menuCheckUpdate}"
IsCancel="True"
IsDefault="True"
Style="{StaticResource MaterialDesignFlatButton}" />

<Button
Grid.Row="2"
<Button
Width="100"
Margin="8"
HorizontalAlignment="Right"
Expand Down
10 changes: 1 addition & 9 deletions v2rayN/v2rayN/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,7 @@ public MainWindow()
this.BindCommand(ViewModel, vm => vm.RebootAsAdminCmd, v => v.menuRebootAsAdmin).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ClearServerStatisticsCmd, v => v.menuClearServerStatistics).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.OpenTheFileLocationCmd, v => v.menuOpenTheFileLocation).DisposeWith(disposables);
//this.BindCommand(ViewModel, vm => vm.ImportOldGuiConfigCmd, v => v.menuImportOldGuiConfig).DisposeWith(disposables);
//check update
//this.BindCommand(ViewModel, vm => vm.CheckUpdateNCmd, v => v.menuCheckUpdateN).DisposeWith(disposables);
//this.BindCommand(ViewModel, vm => vm.CheckUpdateXrayCoreCmd, v => v.menuCheckUpdateXrayCore).DisposeWith(disposables);
//this.BindCommand(ViewModel, vm => vm.CheckUpdateClashMetaCoreCmd, v => v.menuCheckUpdateMihomoCore).DisposeWith(disposables);
//this.BindCommand(ViewModel, vm => vm.CheckUpdateSingBoxCoreCmd, v => v.menuCheckUpdateSingBoxCore).DisposeWith(disposables);
//this.BindCommand(ViewModel, vm => vm.CheckUpdateGeoCmd, v => v.menuCheckUpdateGeo).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.BlReloadEnabled, v => v.menuReload.IsEnabled).DisposeWith(disposables);
Expand Down

0 comments on commit 7901a59

Please sign in to comment.