Skip to content

Commit e982d1d

Browse files
committed
feat: Checking the return value of the "before script" close #376
1 parent f93e709 commit e982d1d

File tree

8 files changed

+48
-19
lines changed

8 files changed

+48
-19
lines changed

Ui/Model/Protocol/Base/ProtocolBase.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,21 +291,24 @@ public ProtocolBase Clone()
291291
return clone;
292292
}
293293

294-
public void RunScriptBeforeConnect()
294+
public int RunScriptBeforeConnect()
295295
{
296+
int exitCode = 0;
296297
try
297298
{
298299
if (!string.IsNullOrWhiteSpace(CommandBeforeConnected))
299300
{
300301
var tuple = WinCmdRunner.DisassembleOneLineScriptCmd(CommandBeforeConnected);
301-
WinCmdRunner.RunFile(tuple.Item1, arguments: tuple.Item2, isAsync: false, isHideWindow: HideCommandBeforeConnectedWindow);
302+
exitCode = WinCmdRunner.RunFile(tuple.Item1, arguments: tuple.Item2, isAsync: false, isHideWindow: HideCommandBeforeConnectedWindow);
302303
}
303304
}
304305
catch (Exception e)
305306
{
307+
exitCode = 1;
306308
SimpleLogHelper.Error(e);
307309
MessageBoxHelper.ErrorAlert(e.Message, IoC.Get<ILanguageService>().Translate("Script before connect"));
308310
}
311+
return exitCode;
309312
}
310313

311314
public void RunScriptAfterDisconnected()

Ui/Service/DataSource/DataSourceService.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,26 @@ public static List<DataSourceBase> AdditionalSourcesLoadFromProfile(string path)
160160

161161
public static void AdditionalSourcesSaveToProfile(string path, List<DataSourceBase> sources)
162162
{
163-
if (sources.Count == 0)
163+
try
164164
{
165-
var fi = new FileInfo(path);
166-
if (fi.Exists)
167-
fi.Delete();
165+
if (sources.Count == 0)
166+
{
167+
var fi = new FileInfo(path);
168+
if (fi.Exists)
169+
fi.Delete();
170+
}
171+
else
172+
{
173+
var fi = new FileInfo(path);
174+
if (fi?.Directory?.Exists == false)
175+
fi.Directory.Create();
176+
if (IoPermissionHelper.HasWritePermissionOnFile(path))
177+
File.WriteAllText(path, JsonConvert.SerializeObject(sources, Formatting.Indented), Encoding.UTF8);
178+
}
168179
}
169-
else
180+
finally
170181
{
171-
var fi = new FileInfo(path);
172-
if (fi?.Directory?.Exists == false)
173-
fi.Directory.Create();
174-
File.WriteAllText(path, JsonConvert.SerializeObject(sources, Formatting.Indented), Encoding.UTF8);
182+
175183
}
176184
}
177185
}

Ui/Service/LanguageService.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public bool SetLanguage(string code)
153153
#endif
154154
}
155155

156-
_applicationResourceDictionary?.ChangeLanguage(resource);
156+
_applicationResourceDictionary.ChangeLanguage(resource);
157157
GlobalEventHelper.OnLanguageChanged?.Invoke();
158158
return true;
159159
}
@@ -166,11 +166,14 @@ public string Translate(Enum e)
166166

167167
public string Translate(string key)
168168
{
169+
if (string.IsNullOrEmpty(key) || _applicationResourceDictionary == null)
170+
return key;
171+
169172
key = key.Trim(new[] { '\'' });
170173
if (_applicationResourceDictionary.Contains(key))
171174
return _applicationResourceDictionary[key].ToString() ?? key;
172175

173-
MsAppCenterHelper.Error(new DirectoryNotFoundException($"int {_languageCode}, key not found: {key}"));
176+
MsAppCenterHelper.Error(new Exception($"int {_languageCode}, key not found: {key}"));
174177
#if DEBUG
175178
var tw = new StreamWriter("need translation " + _languageCode + ".txt", true);
176179
tw.WriteLine(key);

Ui/Service/SessionControlService_OpenConnection.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading;
66
using System.Threading.Tasks;
77
using System.Windows;
8+
using _1RM.Model.DAO.Dapper;
89
using _1RM.Model.Protocol;
910
using _1RM.Model.Protocol.Base;
1011
using _1RM.Model.ProtocolRunner;
@@ -196,7 +197,14 @@ private void Connect(in ProtocolBase protocol, in string fromView, in string ass
196197
}
197198

198199
// run script before connected
199-
protocolClone.RunScriptBeforeConnect();
200+
{
201+
int code = protocolClone.RunScriptBeforeConnect();
202+
if (0 != code)
203+
{
204+
MessageBoxHelper.ErrorAlert($"Script ExitCode = {code}, connection abort!");
205+
return;
206+
}
207+
}
200208

201209
// dispatch for specified protocol
202210
if (protocolClone is RdpApp rdpApp)

Ui/Utils/MsAppCenterHelper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ public static void Error(Exception e, IDictionary<string, string>? properties =
4848
properties ??= new Dictionary<string, string>();
4949
if(!properties.ContainsKey("Version"))
5050
properties.Add("Version", AppVersion.Version);
51-
Crashes.TrackError(e, properties, attachments?.ToArray());
51+
if (attachments != null)
52+
Crashes.TrackError(e, properties, attachments.ToArray());
53+
else
54+
Crashes.TrackError(e, properties);
5255
#endif
5356
}
5457

Ui/View/Editor/ServerEditorPageViewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,11 @@ public RelayCommand CmdTestScript
668668
MessageBoxHelper.Info($"We will run: '{tuple.Item1}' with parameters '{tuple.Item2}'");
669669
else
670670
MessageBoxHelper.Info($"We will run: '{cmd}'");
671-
WinCmdRunner.RunFile(tuple.Item1, arguments: tuple.Item2, isHideWindow: false);
671+
var code = WinCmdRunner.RunFile(tuple.Item1, arguments: tuple.Item2, isHideWindow: false);
672+
if (code != 0)
673+
{
674+
MessageBoxHelper.Info($"Exit code: {code}");
675+
}
672676
}
673677
}
674678
catch (Exception ex)

Ui/View/Launcher/ServerSelectionsViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ public void CalcVisibleByFilter()
233233
if (string.IsNullOrEmpty(keyword))
234234
{
235235
RebuildVmServerList();
236+
TagFilters = new List<TagFilter>();
236237
return;
237238
}
238239

readme.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1Remote.
1+
# 1Remote
22

33
English | [中文](https://github.com/1Remote/1Remote/wiki/Intro-%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)
44

@@ -24,13 +24,12 @@ This App Will Rename to 1Remote in the feature..
2424
- Detailed connection configuration: tags, icons, colors, connection scripts etc.
2525
- Multiple languages, themes and tabbed interface
2626
- [Import connections from mRemoteNG](https://raw.githubusercontent.com/1Remote/PRemoteM/Doc/DocPic/Migrate.jpg)
27-
- [Password encryption via RSA](https://github.com/1Remote/1Remote/wiki/Security)
2827
- Customizable runners, in SFTP \ FTP \ VNC \ etc. protocols, you can replace the internal runner with your favourite tools.[wiki](https://github.com/1Remote/1Remote/wiki/%5BProtocol%5D--Protocol-Runners)
2928
- Portable - just unpack and run
3029

3130
## Installation
3231

33-
Latest Version: 0.7.2.6
32+
Latest Version: 0.7.2.7
3433

3534
Use one of the following methods to install the application:
3635

0 commit comments

Comments
 (0)