|
5 | 5 | using uplink.NET.Interfaces; |
6 | 6 | using uplink.NET.Models; |
7 | 7 | using uplink.NET.Services; |
| 8 | +using static System.Environment; |
8 | 9 |
|
9 | 10 | var assembly = Assembly.GetExecutingAssembly(); |
10 | 11 | var assemblyVersion = assembly.GetName().Version; |
11 | 12 | Console.ForegroundColor = ConsoleColor.Blue; |
12 | | -Console.WriteLine($"\nWelcome to Quickshare v{assemblyVersion.Major}.{assemblyVersion.Minor}.{assemblyVersion.Build} powered by Storj DCS (https://storj.io)!\n"); |
| 13 | +Console.WriteLine($"\nWelcome to Quickshare v{assemblyVersion.Major}.{assemblyVersion.Minor}.{assemblyVersion.Build} powered by Storj DCS (https://storj.io)!"); |
| 14 | +Console.WriteLine($"It is using uplink-c {uplink.NET.Models.Access.GetStorjVersion()} and Go {uplink.NET.Models.Access.GetGoVersion()}\n"); |
13 | 15 | Console.ForegroundColor = ConsoleColor.Gray; |
14 | 16 |
|
15 | | -string configLocation = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + @"\quickshare.config"; |
16 | | -if (!File.Exists(configLocation)) |
| 17 | +string appData = Path.Combine(Environment.GetFolderPath(SpecialFolder.LocalApplicationData, SpecialFolderOption.DoNotVerify), "quickshare"); |
| 18 | +if (!Directory.Exists(appData)) |
17 | 19 | { |
| 20 | + Directory.CreateDirectory(appData); |
| 21 | +} |
| 22 | + |
| 23 | +string configLocation = Path.Combine(appData, @"\quickshare.config"); |
| 24 | + |
| 25 | +//Check if the user wants to set new config-values |
| 26 | +bool requestsConfigUpdate = false; |
| 27 | +Parser.Default.ParseArguments<CommandLineConfigOptions>(args) |
| 28 | + .WithParsed(o => |
| 29 | + { |
| 30 | + requestsConfigUpdate = true; |
| 31 | + }); |
| 32 | + |
| 33 | +if (!File.Exists(configLocation) || requestsConfigUpdate) |
| 34 | +{ |
| 35 | + //There is no config or the user explicitly wants to set new values |
18 | 36 | Parser.Default.ParseArguments<CommandLineConfigOptions>(args) |
19 | 37 | .WithParsed(o => |
20 | 38 | { |
21 | 39 | var quickshareConfig = new QuickshareConfig { AccessGrant = o.AccessGrant, BucketName = o.BucketName }; |
22 | 40 | var configJson = JsonConvert.SerializeObject(quickshareConfig); |
23 | 41 | File.WriteAllText(configLocation, configJson); |
24 | 42 |
|
25 | | - Console.WriteLine("Your configuration has been set! You may now use 'quickshare FILENAME' to share a file."); |
| 43 | + Console.WriteLine("Your configuration has been set! You may now use 'quickshare -f FILENAME' to share a file. Add something like '-d \"1 week\" to restrict the availability of your file and delete it automatically."); |
26 | 44 | }) |
27 | 45 | .WithNotParsed(o => |
28 | 46 | { |
|
45 | 63 | if (!string.IsNullOrEmpty(s.Duration)) |
46 | 64 | { |
47 | 65 | var parsed = TimeSpanParserUtil.TimeSpanParser.TryParse(s.Duration, out shareDuration); |
48 | | - if(!parsed) |
| 66 | + if (!parsed) |
49 | 67 | { |
50 | 68 | Console.ForegroundColor = ConsoleColor.Red; |
51 | 69 | Console.WriteLine("Could not parse the share-duration. Please try a different expression."); |
|
63 | 81 | Console.WriteLine("Starting upload..."); |
64 | 82 | IObjectService objectService = new ObjectService(access); |
65 | 83 | var uploadOptions = new UploadOptions(); |
66 | | - if(shareDuration != TimeSpan.MinValue) |
| 84 | + if (shareDuration != TimeSpan.MinValue) |
67 | 85 | { |
68 | 86 | uploadOptions.Expires = DateTime.Now + shareDuration; |
69 | 87 | } |
|
98 | 116 | Console.WriteLine(url); |
99 | 117 | TextCopy.ClipboardService.SetText(url); |
100 | 118 | Console.WriteLine("It has been copied to the clipboard."); |
101 | | - if(shareDuration != TimeSpan.MinValue) |
| 119 | + if (shareDuration != TimeSpan.MinValue) |
102 | 120 | { |
103 | 121 | Console.ForegroundColor = ConsoleColor.Magenta; |
104 | 122 | Console.WriteLine("Your shared file will expire on {0}. The file will be automatically deleted afterwards.", uploadOptions.Expires.ToString()); |
|
0 commit comments