Skip to content

Commit 64a5168

Browse files
committed
get running on linux
1 parent a20b262 commit 64a5168

File tree

26 files changed

+221
-100
lines changed

26 files changed

+221
-100
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace FileSystemCommon.Models.Configuration
2+
{
3+
public class Config
4+
{
5+
public char DirectorySeparatorChar { get; set; }
6+
7+
public char AltDirectorySeparatorChar { get; set; }
8+
}
9+
}

FileSystemCommon/Utils.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Linq;
66
using FileSystemCommon.Models.FileSystem;
7+
using FileSystemCommon.Models.Configuration;
78

89
namespace FileSystemCommon
910
{
@@ -136,34 +137,32 @@ public static string ToPath(this IEnumerable<PathPart> parts)
136137
return parts?.LastOrDefault().Path ?? string.Empty;
137138
}
138139

139-
public static string JoinPaths(params string[] paths)
140+
public static string JoinPaths(this Config config, params string[] paths)
140141
{
141-
return JoinPaths((IEnumerable<string>)paths);
142+
return JoinPaths(config, (IEnumerable<string>)paths);
142143
}
143144

144-
public static string JoinPaths(IEnumerable<string> paths)
145+
public static string JoinPaths(this Config config, IEnumerable<string> paths)
145146
{
146147
IEnumerable<string> parts = paths?.Select(TrimPath).Where(p => !string.IsNullOrEmpty(p));
147148
return parts == null
148149
? string.Empty
149-
: string.Join(Path.DirectorySeparatorChar.ToString(), parts);
150+
: string.Join(config.DirectorySeparatorChar.ToString(), parts);
150151

151152
string TrimPath(string path)
152153
{
153-
return path?.Trim(' ', Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
154+
return path?.Trim(' ', config.DirectorySeparatorChar, config.AltDirectorySeparatorChar);
154155
}
155156
}
156157

157-
public static string[] SplitPath(string path)
158+
public static string[] SplitVirtualPath(this Config config, string path)
158159
{
159-
return path
160-
.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)
161-
.Split(Path.DirectorySeparatorChar);
160+
return path.Split(new char[] { config.DirectorySeparatorChar, config.AltDirectorySeparatorChar }, 2);
162161
}
163162

164-
public static string GetParentPath(string path)
163+
public static string GetParentPath(this Config config, string path)
165164
{
166-
int index = path.LastIndexOf(Path.DirectorySeparatorChar);
165+
int index = path.LastIndexOf(config.DirectorySeparatorChar);
167166
return index == -1 ? string.Empty : path.Substring(0, index + 1);
168167
}
169168

FileSystemUWP/API/Api.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FileSystemCommon;
22
using FileSystemCommon.Models.Auth;
3+
using FileSystemCommon.Models.Configuration;
34
using FileSystemCommon.Models.FileSystem.Content;
45
using FileSystemCommon.Models.FileSystem.Files;
56
using FileSystemCommon.Models.FileSystem.Folders;
@@ -28,8 +29,15 @@ public class Api
2829

2930
public string[] RawCookies { get; set; }
3031

32+
public Config Config { get; private set; }
33+
3134
public Api()
3235
{
36+
Config = new Config()
37+
{
38+
DirectorySeparatorChar = '/',
39+
AltDirectorySeparatorChar = '/',
40+
};
3341
}
3442

3543
internal Api Clone()
@@ -40,6 +48,11 @@ internal Api Clone()
4048
BaseUrl = BaseUrl,
4149
Username = Username,
4250
RawCookies = RawCookies?.ToArray(),
51+
Config = new Config()
52+
{
53+
DirectorySeparatorChar = Config?.DirectorySeparatorChar ?? '/',
54+
AltDirectorySeparatorChar = Config?.AltDirectorySeparatorChar ?? '/',
55+
},
4356
};
4457
}
4558

@@ -83,6 +96,13 @@ public async Task<bool> Login(LoginBody body)
8396
}
8497
}
8598

99+
public async Task<bool> LoadConfig()
100+
{
101+
Uri uri = GetUri("/api/config");
102+
Config = await Request<Config>(uri, HttpMethod.Get);
103+
return Config != null;
104+
}
105+
86106
public Task<bool> FolderExists(string path)
87107
{
88108
if (string.IsNullOrWhiteSpace(path)) return Task.FromResult(false);

FileSystemUWP/App.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs
218218
while (syncs.Count > 0)
219219
{
220220
SyncPairHandler handler = syncs.Dequeue();
221-
if (!await handler.Api.IsAuthorized()) continue;
221+
if (!await handler.Api.IsAuthorized() && await handler.Api.LoadConfig()) continue;
222+
222223
await handler.Start();
223224

224225
SyncPair sync;

FileSystemUWP/FileSystemItemInfoPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private async void Page_Loaded(object sender, RoutedEventArgs e)
5656

5757
private object PathConverter_ConvertEvent(object value, Type targetType, object parameter, string language)
5858
{
59-
return ((PathPart[])value).Select(p => p.Name).Join("\\");
59+
return ((PathPart[])value).Select(p => p.Name).Join(api.Config.DirectorySeparatorChar.ToString());
6060
}
6161

6262
private object SizeCon_ConvertEvent(object value, Type targetType, object parameter, string language)

FileSystemUWP/Picker/NamePickerPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private async void TbxName_TextChanged(object sender, TextChangedEventArgs e)
5151
prgLoading.IsActive = true;
5252
abbAccept.IsEnabled = false;
5353

54-
string path = Utils.JoinPaths(picking.FolderPath, name);
54+
string path = picking.Api.Config.JoinPaths(picking.FolderPath, name);
5555
Task<bool> fileExistsTask = picking.Api.FileExists(path);
5656
Task<bool> folderExistsTask = picking.Api.FolderExists(path);
5757
bool fileExists = await fileExistsTask;

FileSystemUWP/Picker/PickerControl.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private static void OnCurrentFolderPropertyChanged(DependencyObject sender, Depe
3434
PickerControl s = (PickerControl)sender;
3535
FileSystemItem? value = (FileSystemItem?)e.NewValue;
3636

37-
s.CurrentFolderNamePath = value?.PathParts.GetNamePath();
37+
s.CurrentFolderNamePath = value?.PathParts.GetNamePath(s.Api.Config.DirectorySeparatorChar);
3838
}
3939

4040
public static readonly DependencyProperty CurrentFolderNamePathProperty = DependencyProperty.Register("CurrentFolderNamePath",

FileSystemUWP/Picker/PickerPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private async void AbbSelect_Click(object sender, RoutedEventArgs e)
7878

7979
if (!namePicking.Task.IsCompleted) return;
8080

81-
string path = Utils.JoinPaths(pcView.CurrentFolder?.FullPath, name);
81+
string path = picking.Api.Config.JoinPaths(pcView.CurrentFolder?.FullPath, name);
8282
picking.SetResult(path);
8383
Frame.GoBack();
8484
break;

FileSystemUWP/ServerExplorerPage.xaml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ private async Task<bool> CheckServerConnection()
108108
private static async Task<bool> Ping(Api api)
109109
{
110110
return !string.IsNullOrWhiteSpace(api.BaseUrl) &&
111-
await api.IsAuthorized();
111+
await api.IsAuthorized() &&
112+
await api.LoadConfig();
112113
}
113114

114115
private async void CallApiSettingsPage()
@@ -336,7 +337,7 @@ private async void AbbNewFolder_Click(object sender, RoutedEventArgs e)
336337
name = tbx.Text.Trim();
337338
if (name.Length == 0 || name.Any(c => Path.GetInvalidFileNameChars().Contains(c))) continue;
338339

339-
string path = Utils.JoinPaths(pcView.CurrentFolder.Value.FullPath, name);
340+
string path = viewModel.Api.Config.JoinPaths(pcView.CurrentFolder.Value.FullPath, name);
340341

341342
await UiUtils.TryAgain("Try again?", "Create folder error",
342343
() => viewModel.Api.CreateFolder(path),
@@ -358,7 +359,7 @@ private async void AbbUploadFile_Click(object sender, RoutedEventArgs e)
358359
picker.FileTypeFilter.Add("*");
359360

360361
StorageFile srcFile = await picker.PickSingleFileAsync();
361-
string path = Utils.JoinPaths(pcView.CurrentFolder.Value.FullPath, srcFile.Name);
362+
string path = viewModel.Api.Config.JoinPaths(pcView.CurrentFolder.Value.FullPath, srcFile.Name);
362363

363364
await UiUtils.TryAgain("Try again?", "Uplaod file error",
364365
() => viewModel.Api.UploadFile(path, srcFile),

FileSystemUWP/Sync/Definitions/SyncEditPage.xaml.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using FileSystemCommon;
2+
using FileSystemCommon.Models.Configuration;
23
using FileSystemCommon.Models.FileSystem;
34
using FileSystemCommon.Models.FileSystem.Content;
45
using FileSystemCommon.Models.FileSystem.Folders;
@@ -63,19 +64,23 @@ public SyncEditPage()
6364
protected override void OnNavigatedTo(NavigationEventArgs e)
6465
{
6566
edit = (SyncPairEdit)e.Parameter;
67+
char directorySeparatorChar = edit.Api.Config.DirectorySeparatorChar;
6668

6769
PathPart[] serverPath = edit.Sync.ServerPath;
6870
if (serverPath != null)
6971
{
7072
for (int i = 0; i < serverPath.Length; i++)
7173
{
72-
folderPaths[serverPath.Take(i + 1).GetNamePath().TrimEnd('\\')] = serverPath[i].Path;
74+
string path = serverPath
75+
.Take(i + 1)
76+
.GetNamePath(directorySeparatorChar);
77+
folderPaths[path] = serverPath[i].Path;
7378
}
7479
}
7580

7681
tblTitlePrefix.Text = edit.IsAdd ? "Add" : "Edit";
7782
DataContext = edit.Sync;
78-
asbServerPath.Text = edit.Sync.ServerPath.GetNamePath();
83+
asbServerPath.Text = edit.Sync.ServerPath.GetNamePath(directorySeparatorChar);
7984

8085
base.OnNavigatedTo(e);
8186
}
@@ -103,6 +108,7 @@ private object LinesConverter_ConvertBackEvent(object value, Type targetType, ob
103108

104109
private async void AsbServerPath_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
105110
{
111+
Config config = edit.Api.Config;
106112
sinServerPathValid.Symbol = Symbol.Help;
107113

108114
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput ||
@@ -113,15 +119,18 @@ private async void AsbServerPath_TextChanged(AutoSuggestBox sender, AutoSuggestB
113119
string.Empty : Path.GetFileName(sender.Text);
114120
string searchKey = folderName.ToLower();
115121
string parentPath = string.IsNullOrWhiteSpace(sender.Text) ?
116-
string.Empty : Utils.GetParentPath(sender.Text).TrimEnd(Path.DirectorySeparatorChar);
122+
string.Empty : config.GetParentPath(sender.Text).TrimEnd(config.DirectorySeparatorChar);
117123
FolderContent content = folderPaths.TryGetValue(parentPath, out actualParentPath) ?
118124
await edit.Api.FolderContent(folderPaths[parentPath]) : null;
119125

120126
if (content?.Folders != null)
121127
{
122128
foreach (FolderSortItem folder in content.Folders)
123129
{
124-
folderPaths[content.Path.GetChildPathParts(folder).GetNamePath().TrimEnd(Path.DirectorySeparatorChar)] = folder.Path;
130+
string path = content.Path
131+
.GetChildPathParts(folder)
132+
.GetNamePath(config.DirectorySeparatorChar);
133+
folderPaths[path] = folder.Path;
125134
}
126135

127136
FolderSortItem currentFolder;
@@ -143,17 +152,18 @@ private async void AsbServerPath_TextChanged(AutoSuggestBox sender, AutoSuggestB
143152
}
144153

145154
string actualPath;
146-
string namePath = sender.Text.TrimEnd(Path.DirectorySeparatorChar);
155+
string namePath = sender.Text.TrimEnd(config.DirectorySeparatorChar);
147156
bool exists = folderPaths.TryGetValue(namePath, out actualPath) && await edit.Api.FolderExists(actualPath);
148157
sinServerPathValid.Symbol = exists ? Symbol.Accept : Symbol.Dislike;
149158
}
150159

151160
private void AsbServerPath_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
152161
{
162+
Config config = edit.Api.Config;
153163
FolderItem suggestion = args.ChosenSuggestion is FolderItem ? (FolderItem)args.ChosenSuggestion : (FolderItem)sender.Items[0];
154-
string parentPath = Utils.GetParentPath(sender.Text);
164+
string parentPath = config.GetParentPath(sender.Text);
155165

156-
sender.Text = Utils.JoinPaths(parentPath, suggestion.Name) + '\\';
166+
sender.Text = config.JoinPaths(parentPath, suggestion.Name) + config.DirectorySeparatorChar;
157167
sender.Focus(FocusState.Keyboard);
158168
}
159169

0 commit comments

Comments
 (0)