Skip to content

Commit 63b109f

Browse files
committed
fix: bugs from AppCenter
1 parent f1545e1 commit 63b109f

File tree

7 files changed

+67
-26
lines changed

7 files changed

+67
-26
lines changed

Ui/Model/Protocol/FileTransmit/Transmitters/TransmissionController/TransmitTask.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -542,27 +542,30 @@ private bool CheckExistedFiles(IEnumerable<RemoteItem> remoteItems)
542542

543543
private void DataTransmitting(ref TransmitItem item, ulong readLength)
544544
{
545-
try
545+
lock (item)
546546
{
547-
if (readLength > item.TransmittedSize && readLength <= item.ByteSize)
547+
try
548548
{
549-
var add = readLength - item.TransmittedSize;
550-
item.TransmittedSize = readLength;
551-
TransmittedByteLength += add;
552-
_transmittedDataLength.Enqueue(new Tuple<DateTime, ulong>(DateTime.Now, add));
553-
RaisePropertyChanged(nameof(TransmitSpeed));
554-
SimpleLogHelper.Debug($"{DateTime.Now}: {TransmittedByteLength}done, {TransmittedPercentage}%");
549+
if (readLength > item.TransmittedSize && readLength <= item.ByteSize)
550+
{
551+
var add = readLength - item.TransmittedSize;
552+
item.TransmittedSize = readLength;
553+
TransmittedByteLength += add;
554+
_transmittedDataLength.Enqueue(new Tuple<DateTime, ulong>(DateTime.Now, add));
555+
RaisePropertyChanged(nameof(TransmitSpeed));
556+
SimpleLogHelper.Debug($"{DateTime.Now}: {TransmittedByteLength}done, {TransmittedPercentage}%");
557+
}
555558
}
556-
}
557-
catch (Exception e)
558-
{
559-
MsAppCenterHelper.Error(e, new Dictionary<string, string>()
559+
catch (Exception e)
560560
{
561-
{"readLength", readLength.ToString()},
562-
{"item.TransmittedSize", item.TransmittedSize.ToString()},
563-
{"item.ByteSize", item.ByteSize.ToString()},
564-
});
565-
SimpleLogHelper.Fatal(e, $"readLength = {readLength}, item.TransmittedSize = {item.TransmittedSize}, item.ByteSize = {item.ByteSize}");
561+
MsAppCenterHelper.Error(e, new Dictionary<string, string>()
562+
{
563+
{"readLength", readLength.ToString()},
564+
{"item.TransmittedSize", item.TransmittedSize.ToString()},
565+
{"item.ByteSize", item.ByteSize.ToString()},
566+
});
567+
SimpleLogHelper.Fatal(e, $"readLength = {readLength}, item.TransmittedSize = {item.TransmittedSize}, item.ByteSize = {item.ByteSize}");
568+
}
566569
}
567570
}
568571

Ui/Model/Protocol/FileTransmit/Transmitters/TransmitterSFtp.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public TransmitterSFtp(string host, int port, string username, string key, bool
4444
{
4545
lock (this)
4646
{
47-
_sftp?.Dispose();
47+
var sftp = _sftp;
48+
_sftp = null;
49+
sftp?.Dispose();
4850
}
4951
}
5052

Ui/Utils/SetSelfStartingHelper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ private static void SetSelfStartByShortcut(bool isSetSelfStart, string appName)
150150

151151
try
152152
{
153-
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
154153
if (System.IO.File.Exists(shortcutPath))
155154
{
156155
System.IO.File.Delete(shortcutPath);

Ui/Utils/WindowsApi/WindowsShortcutFactory/WindowsShortcut.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4+
using System.Linq;
45
using System.Runtime.InteropServices;
56

67
namespace _1RM.Utils.WindowsApi.WindowsShortcutFactory
@@ -242,6 +243,24 @@ public static WindowsShortcut Load(string fileName)
242243
/// <exception cref="DirectoryNotFoundException">The directory specified in <paramref name="fileName"/> does not exit.</exception>
243244
public void Save(string fileName)
244245
{
246+
var fi = new FileInfo(fileName);
247+
if (fi.DirectoryName != null)
248+
{
249+
var name = fi.Name;
250+
// if there is special character in the file name, remove them.
251+
if (name.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) >= 0)
252+
{
253+
name = new string(name.Where(c => !System.IO.Path.GetInvalidFileNameChars().Contains(c)).ToArray());
254+
}
255+
// if path is too long, truncate it.
256+
if (name.Length > 200)
257+
{
258+
name = name.Substring(0, 197) + fi.Extension;
259+
}
260+
fileName = System.IO.Path.Combine(fi.DirectoryName, name);
261+
}
262+
263+
245264
if (string.IsNullOrWhiteSpace(fileName))
246265
throw new ArgumentNullException(nameof(fileName));
247266
if (System.IO.Path.IsPathRooted(fileName) && !Directory.Exists(System.IO.Path.GetDirectoryName(fileName)))

Ui/View/Editor/ServerEditorPageViewModel.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public partial class ServerEditorPageViewModel : NotifyPropertyChangedBase
3232
public bool IsAddMode => _serversInBuckEdit == null && Server.IsTmpSession();
3333
public bool IsBuckEdit => IsAddMode == false && _serversInBuckEdit?.Count() > 1;
3434
private readonly ProtocolBase _orgServer; // to remember original protocol's options, for restore data when switching protocols
35-
private readonly ProtocolConfigurationService _protocolConfigurationService = IoC.Get<ProtocolConfigurationService>();
3635

3736

3837

@@ -632,9 +631,9 @@ private void UpdateRunners(string protocolName)
632631
{
633632
var selectedRunner = Server.SelectedRunnerName;
634633
Runners.Clear();
635-
if (_protocolConfigurationService.ProtocolConfigs.ContainsKey(protocolName))
634+
if (IoC.Get<ProtocolConfigurationService>().ProtocolConfigs.ContainsKey(protocolName))
636635
{
637-
var c = _protocolConfigurationService.ProtocolConfigs[protocolName];
636+
var c = IoC.Get<ProtocolConfigurationService>().ProtocolConfigs[protocolName];
638637
Runners.Add("Follow the global settings");
639638
foreach (var runner in c.Runners)
640639
{

Ui/View/Launcher/ServerSelectionsView.xaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ private void TbKeyWord_OnPreviewKeyDown(object sender, KeyEventArgs e)
119119
{
120120
if (tb.CaretIndex == tb.Text.Length)
121121
{
122-
ShowActionsList(vm.SelectedItem ?? vm.VmServerList[vm.SelectedIndex]);
122+
var selected = vm.SelectedItem;
123+
if (selected == null && vm.SelectedIndex >= 0 && vm.SelectedIndex < vm.VmServerList.Count)
124+
{
125+
selected = vm.VmServerList[vm.SelectedIndex];
126+
}
127+
if (selected != null)
128+
ShowActionsList(selected);
123129
return;
124130
}
125131
}

Ui/View/ServerList/ServerListPageViewModel.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,23 @@ public void RefreshCollectionViewSource(bool force = false)
460460
for (int i = 0; i < servers.Count; i++)
461461
{
462462
var vm = servers[i];
463-
if (IsServerVisible.ContainsKey(vm))
464-
IsServerVisible[vm] = matchResults[i].Item1;
463+
if (i < 0 || i >= matchResults.Count)
464+
{
465+
// we get error report here that i is out of range, so we add this check 2024.10.31 https://appcenter.ms/users/VShawn/apps/1Remote-1/crashes/errors/859400306/overview
466+
MsAppCenterHelper.Error(new Exception($"MatchKeywords: i({i}) is out of range(0-{matchResults.Count})"), new Dictionary<string, string>()
467+
{
468+
{"filter", filter},
469+
{"servers.Count", servers.Count.ToString()},
470+
});
471+
continue;
472+
}
465473
else
466-
IsServerVisible.Add(vm, matchResults[i].Item1);
474+
{
475+
if (IsServerVisible.ContainsKey(vm))
476+
IsServerVisible[vm] = matchResults[i].Item1;
477+
else
478+
IsServerVisible.Add(vm, matchResults[i].Item1);
479+
}
467480
}
468481
}
469482

0 commit comments

Comments
 (0)