Skip to content

Commit ef5a206

Browse files
committed
Projektdateien hinzufügen.
1 parent a257b71 commit ef5a206

File tree

6 files changed

+193
-0
lines changed

6 files changed

+193
-0
lines changed

Quickshare.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32721.290
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Quickshare", "Quickshare\Quickshare.csproj", "{9FF69CA5-68D7-400C-9665-3361E29B0E98}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{9FF69CA5-68D7-400C-9665-3361E29B0E98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9FF69CA5-68D7-400C-9665-3361E29B0E98}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9FF69CA5-68D7-400C-9665-3361E29B0E98}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{9FF69CA5-68D7-400C-9665-3361E29B0E98}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {ED89B5FE-45DC-4F7F-821E-4659FA372553}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using CommandLine.Text;
2+
using CommandLine;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Quickshare
10+
{
11+
[Verb("config", HelpText = "Configure Quickshare.")]
12+
public class CommandLineConfigOptions
13+
{
14+
[Option('g', "access-grant", Required = true, HelpText = "The access grant on Storj DCS, that should be used.")]
15+
public string AccessGrant { get; set; }
16+
17+
[Option('b', "bucket-name", Required = true, HelpText = "The name of the bucket that should be used.")]
18+
public string BucketName { get; set; }
19+
}
20+
}

Quickshare/CommandLineShareOptions.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using CommandLine.Text;
2+
using CommandLine;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Quickshare
10+
{
11+
[Verb("share", isDefault:true, HelpText = "Share a file.")]
12+
public class CommandLineShareOptions
13+
{
14+
[Option('f', "file", Required = true, Default = true, HelpText = "The file to upload.")]
15+
public string Filename { get; set; }
16+
17+
[Option('d', "duration", Required = false, HelpText = "The share-duration.")]
18+
public string Duration { get; set; }
19+
}
20+
}

Quickshare/Program.cs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using CommandLine;
2+
using Newtonsoft.Json;
3+
using Quickshare;
4+
using System.Reflection;
5+
using uplink.NET.Interfaces;
6+
using uplink.NET.Models;
7+
using uplink.NET.Services;
8+
9+
var assembly = Assembly.GetExecutingAssembly();
10+
var assemblyVersion = assembly.GetName().Version;
11+
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.ForegroundColor = ConsoleColor.Gray;
14+
15+
string configLocation = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + @"\quickshare.config";
16+
if (!File.Exists(configLocation))
17+
{
18+
Parser.Default.ParseArguments<CommandLineConfigOptions>(args)
19+
.WithParsed(o =>
20+
{
21+
var quickshareConfig = new QuickshareConfig { AccessGrant = o.AccessGrant, BucketName = o.BucketName };
22+
var configJson = JsonConvert.SerializeObject(quickshareConfig);
23+
File.WriteAllText(configLocation, configJson);
24+
25+
Console.WriteLine("Your configuration has been set! You may now use 'quickshare FILENAME' to share a file.");
26+
})
27+
.WithNotParsed(o =>
28+
{
29+
Console.WriteLine("You need to setup Quickshare first. Call 'quickshare -g ACCESS_GRANT -b BUCKET_NAME'.");
30+
});
31+
}
32+
else
33+
{
34+
var quickshareConfig = JsonConvert.DeserializeObject<QuickshareConfig>(File.ReadAllText(configLocation));
35+
if (quickshareConfig == null)
36+
{
37+
Console.WriteLine("Invalid config. The config has been removed - please re-init quickshare using 'quickshare config'.");
38+
return;
39+
}
40+
41+
var result = Parser.Default.ParseArguments<CommandLineConfigOptions, CommandLineShareOptions>(args);
42+
result.WithParsed<CommandLineShareOptions>(s =>
43+
{
44+
Console.WriteLine("Sharing file '" + s.Filename + "'.");
45+
46+
Access access = new Access(quickshareConfig.AccessGrant);
47+
IBucketService bucketService = new BucketService(access);
48+
Console.WriteLine("Checking bucket...");
49+
var bucket = bucketService.EnsureBucketAsync(quickshareConfig.BucketName).Result;
50+
Console.WriteLine("Starting upload...");
51+
IObjectService objectService = new ObjectService(access);
52+
var uploadOperation = objectService.UploadObjectAsync(bucket, s.Filename, new UploadOptions(), File.ReadAllBytes(s.Filename), false).Result;
53+
uploadOperation.UploadOperationProgressChanged += (uploadOperation) =>
54+
{
55+
if (uploadOperation.PercentageCompleted < 100)
56+
{
57+
Console.ForegroundColor = ConsoleColor.Yellow;
58+
Console.Write("\rStatus: {0}% ", uploadOperation.PercentageCompleted);
59+
}
60+
else
61+
{
62+
Console.ForegroundColor = ConsoleColor.Green;
63+
Console.Write("\rDone! \n");
64+
Console.ForegroundColor = ConsoleColor.Gray;
65+
}
66+
};
67+
uploadOperation.StartUploadAsync().Wait();
68+
69+
if (!uploadOperation.Completed)
70+
{
71+
Console.ForegroundColor = ConsoleColor.Red;
72+
Console.WriteLine("Upload failed: " + uploadOperation.ErrorMessage);
73+
return;
74+
}
75+
76+
Console.WriteLine("Preparing file for sharing...");
77+
var url = access.CreateShareURL(quickshareConfig.BucketName, s.Filename, true, true).Replace("gateway", "link");
78+
Console.WriteLine("Your URL is:");
79+
Console.WriteLine(url);
80+
TextCopy.ClipboardService.SetText(url);
81+
Console.WriteLine("It has been copied to the clipboard.");
82+
});
83+
}
84+
85+

Quickshare/Quickshare.csproj

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<PackAsTool>true</PackAsTool>
9+
<ToolCommandName>quickshare</ToolCommandName>
10+
<PackageOutputPath>./nupkg</PackageOutputPath>
11+
<PackageId>Quickshare</PackageId>
12+
<Title>Quickshare</Title>
13+
<Authors>TopperDEL</Authors>
14+
<Company>TopperDEL</Company>
15+
<Version>0.1.0</Version>
16+
<PackageReleaseNotes>Alpha version</PackageReleaseNotes>
17+
<Description>This package lets you share files quickly by leveraging Storj DCS.</Description>
18+
<Copyright>2022 TopperDEL</Copyright>
19+
</PropertyGroup>
20+
21+
<ItemGroup>
22+
<PackageReference Include="CommandLineParser" Version="2.9.1" />
23+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
24+
<PackageReference Include="TextCopy" Version="6.1.0" />
25+
<PackageReference Include="uplink.NET" Version="2.9.2782" />
26+
<PackageReference Include="uplink.NET.Win" Version="2.9.2782" />
27+
</ItemGroup>
28+
29+
</Project>

Quickshare/QuickshareConfig.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Quickshare
8+
{
9+
public class QuickshareConfig
10+
{
11+
public string AccessGrant { get; set; }
12+
public string BucketName { get; set; }
13+
}
14+
}

0 commit comments

Comments
 (0)