Skip to content

Commit

Permalink
Added scp like uri handling
Browse files Browse the repository at this point in the history
  • Loading branch information
uenz committed Oct 18, 2024
1 parent 5726ada commit 991c6e3
Show file tree
Hide file tree
Showing 21 changed files with 184 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-12,
os: [ # macos-12,
# ubuntu-20.04,
windows-latest
]
Expand Down
9 changes: 4 additions & 5 deletions SparkleShare/Common/AboutController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public class AboutController {

public event UpdateLabelEventDelegate UpdateLabelEvent = delegate { };
public delegate void UpdateLabelEventDelegate (string text);

public readonly string WebsiteLinkAddress = "https://www.sparkleshare.org/";
public readonly string CreditsLinkAddress = "https://github.com/hbons/SparkleShare/blob/master/.github/AUTHORS.md";
public readonly string ReportProblemLinkAddress = "https://www.github.com/hbons/SparkleShare/issues";
// TODO: get link to issues from static configuration
public readonly string WebsiteLinkAddress = "https://github.com/uenz/SparkleShare/wiki";
public readonly string CreditsLinkAddress = "https://github.com/uenz/SparkleShare/blob/master/.github/AUTHORS.md";
public readonly string ReportProblemLinkAddress = "https://www.github.com/uenz/SparkleShare/issues";
public readonly string DebugLogLinkAddress = "file://" + SparkleShare.Controller.Config.LogFilePath;

public string RunningVersion;
Expand Down Expand Up @@ -68,7 +68,6 @@ void CheckForNewVersion ()
HttpClient web_client = new();
var uri = new Uri ("https://www.sparkleshare.org/version");
HttpClient client = new();
HttpResponseMessage response = null!;

try
{
Expand Down
2 changes: 1 addition & 1 deletion SparkleShare/Common/EventLogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public string GetHTMLLog (List<ChangeSet> change_sets)
{
if (change_sets == null || change_sets.Count == 0)
return SparkleShare.Controller.EventLogHTML.Replace ("<!-- $event-log-content -->",
"<div class='day-entry'><div class='day-entry-header'>This project does not keep a history.</div></div>");
"<div class='day-entry'><div class='day-entry-header'>This project does not keep a history.</div></div>").Replace("<!-- $midnight -->", "100000000");

List <ActivityDay> activity_days = new List <ActivityDay> ();

Expand Down
2 changes: 1 addition & 1 deletion SparkleShare/Common/Presets/bitbucket.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</address>
<path>
<value/>
<example>/username/project</example>
<example>:username/project</example>
<uses_lower_case>True</uses_lower_case>
</path>
</preset>
Expand Down
4 changes: 2 additions & 2 deletions SparkleShare/Common/Presets/github.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<fingerprint>b8:d8:95:ce:d9:2c:0a:c0:e1:71:cd:2e:f5:ef:01:ba:34:17:55:4a:4a:64:80:d3:31:cc:c2:be:3d:ed:0f:6b</fingerprint>
</info>
<address>
<value>ssh://[email protected]/</value>
<value>[email protected]/</value>
<example/>
</address>
<path>
<value/>
<example>/username/project</example>
<example>:username/project</example>
</path>
</preset>
</sparkleshare>
4 changes: 2 additions & 2 deletions SparkleShare/Common/Presets/gitlab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<fingerprint>44:e4:05:bc:f4:e1:1a:b5:b8:46:e5:8b:a0:bf:6d:ab:d2:3d:cc:9e:36:7c:ae:17:cb:0c:91:b5:b3:b3:fc:44</fingerprint>
</info>
<address>
<value>ssh://[email protected]/</value>
<value>[email protected]/</value>
<example/>
</address>
<path>
<value/>
<example>/username/project</example>
<example>:username/project</example>
</path>
</preset>
</sparkleshare>
Expand Down
2 changes: 1 addition & 1 deletion SparkleShare/Common/SetupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private void AddPageFetchedDelegate (string remote_url, string [] warnings)
// so the user can easily use the same host again
if (SelectedPresetIndex == 0) {
Preset new_preset;
Uri uri = new Uri (remote_url);
ScpUri uri = new ScpUri (remote_url);

try {
string address = remote_url.Replace (uri.AbsolutePath, "");
Expand Down
7 changes: 3 additions & 4 deletions SparkleShare/Windows/SparkleShare.Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,12 @@
<Compile Remove="SparkleShareInviteOpener\Properties\AssemblyInfo.cs" />
<Compile Remove="SparkleShareInviteOpener\sparkleshare-invite-opener.cs" />
</ItemGroup>
<PropertyGroup />
<PropertyGroup>
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.1" />
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="&quot;$(ProjectDir)postBuild.cmd&quot; &quot;$(TargetDir)git_scm&quot;" />
</Target>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="&quot;$(ProjectDir)postBuild.cmd&quot; &quot;$(TargetDir)git_scm&quot;" />
</Target>
Expand Down
15 changes: 9 additions & 6 deletions SparkleShare/Windows/UserInterface/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,20 @@ public override void OpenFile (string path)

public override void OpenFolder (string path)
{
var psi = new ProcessStartInfo(path)
{
UseShellExecute = true
};
Process.Start (path);
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName =path;
startInfo.WorkingDirectory =path;
startInfo.UseShellExecute = true;
Process.Start(startInfo);
}


public override void OpenWebsite (string url)
{
Process.Start (new ProcessStartInfo (url));
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = url;
startInfo.UseShellExecute = true;
Process.Start(startInfo);
}


Expand Down
6 changes: 5 additions & 1 deletion SparkleShare/Windows/UserInterface/EventLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ private void UpdateContent(string html)
html = html.Replace("<!-- $document-edited-background-image -->", pixmaps_path + "/document-edited-12.png");
html = html.Replace("<!-- $document-deleted-background-image -->", pixmaps_path + "/document-deleted-12.png");
html = html.Replace("<!-- $document-moved-background-image -->", pixmaps_path + "/document-moved-12.png");

html.Replace("<!-- $midnight -->", "100000000");
using (StreamWriter outputFile = new StreamWriter(System.IO.Path.Combine(@"c:\temp", "page.html")))
{
outputFile.WriteLine(html);
}
this.spinner.Stop();

this.webbrowser.ObjectForScripting = new SparkleScriptingObject();
Expand Down
1 change: 0 additions & 1 deletion SparkleShare/Windows/UserInterface/NotifyIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ private Forms.NotifyIcon Notification {
public NotifyIcon() {
VisibilityProperty.OverrideMetadata(typeof(NotifyIcon), new PropertyMetadata(OnVisibilityChanged));

// TODO ContextMenu wird nicht mehr unterstützt. Verwenden Sie stattdessen ContextMenuStrip. Weitere Informationen finden Sie unter: https://docs.microsoft.com/en-us/dotnet/core/compatibility/winforms#removed-controls
Notification = new Forms.NotifyIcon {
Text = Text,
Visible = true,
Expand Down
2 changes: 1 addition & 1 deletion SparkleShare/Windows/git.download
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/git-for-windows/git/releases/download/v2.47.0.windows.1/PortableGit-2.47.0-64-bit.7z.exe 0b7fcd76902ebde5b4c00ebae597d7f65dff8c3dd0ae59f5059e1aaa3adace87
https://github.com/git-for-windows/git/releases/download/v2.26.1.windows.1/PortableGit-2.26.1-32-bit.7z.exe 862fa87cb4c00872055efbdbf3ed0d5e87838605bb0c3024bed3b32acf43cc0c
10 changes: 5 additions & 5 deletions Sparkles/BaseFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public abstract class BaseFetcher
public readonly List<StorageTypeInfo> AvailableStorageTypes = new List<StorageTypeInfo>();


public Uri RemoteUrl { get; protected set; }
public ScpUri RemoteUrl { get; protected set; }
public string RequiredFingerprint { get; protected set; }
public readonly bool FetchPriorHistory;
public string TargetFolder { get; protected set; }
Expand Down Expand Up @@ -109,16 +109,16 @@ protected BaseFetcher(SparkleFetcherInfo info)

if (address.EndsWith("/", StringComparison.InvariantCulture))
address = address.Substring(0, address.Length - 1);

/*
if (!remote_path.StartsWith("/", StringComparison.InvariantCulture))
remote_path = "/" + remote_path;
remote_path = "/" + remote_path;*/

if (!address.Contains("://"))
address = "ssh://" + address;

TargetFolder = info.TargetDirectory;

RemoteUrl = new Uri (address + remote_path);
RemoteUrl = new ScpUri (address + remote_path);
IsActive = false;
}

Expand Down Expand Up @@ -210,7 +210,7 @@ void CreateInitialChangeSet()
string n = Environment.NewLine;
string file_path = Path.Combine(TargetFolder, "SparkleShare.txt");

var uri_builder = new UriBuilder(RemoteUrl);
var uri_builder = new UriBuilder(RemoteUrl.ToString());

// Don't expose possible username or password
if (RemoteUrl.Scheme.StartsWith("http", StringComparison.InvariantCultureIgnoreCase))
Expand Down
4 changes: 2 additions & 2 deletions Sparkles/BaseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public abstract class BaseRepository

public readonly string LocalPath;
public readonly string Name;
public readonly Uri RemoteUrl;
public readonly ScpUri RemoteUrl;
public List<ChangeSet> ChangeSets { get; set; } = null!;
public SyncStatus Status { get; set; }
public ErrorStatus Error { get; protected set; }
Expand Down Expand Up @@ -206,7 +206,7 @@ public BaseRepository(string path, Configuration config)
this.local_config = config;
LocalPath = path;
Name = Path.GetFileName(LocalPath);
RemoteUrl = new Uri(this.local_config.UrlByName(Name)!);
RemoteUrl = new ScpUri(this.local_config.UrlByName(Name)!);
IsBuffering = false;
this.identifier = Identifier;

Expand Down
4 changes: 2 additions & 2 deletions Sparkles/ChangeSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ChangeSet
public string Revision = null!;
public DateTime Timestamp;
public DateTime FirstTimestamp;
public Uri RemoteUrl = null!;
public ScpUri RemoteUrl = null!;

public List<Change> Changes = new List<Change>();

Expand Down Expand Up @@ -92,7 +92,7 @@ public string FullPath
return Path.Combine(custom_path, Name);

return Path.Combine(Configuration.DefaultConfiguration.FoldersPath,
new Uri(Configuration.DefaultConfiguration.UrlByName(Name)!).Host,
new ScpUri(Configuration.DefaultConfiguration.UrlByName(Name)!).Host,
Name);
}
}
Expand Down
15 changes: 10 additions & 5 deletions Sparkles/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public class Configuration : XmlDocument

if (InstallationInfo.OperatingSystem != OS.Windows && InstallationInfo.OperatingSystem != OS.macOS)
app_data_path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), ".config");
// TODO: Compiler switch
//string config_path = Path.Combine(app_data_path, "org.sparkleshare.SparkleShare");
// TODO: rename Compiler switch
#if DEBUG
string config_path = Path.Combine(app_data_path, "org.debug.sparkleshare.SparkleShare");

#else
string config_path = Path.Combine(app_data_path, "org.sparkleshare.SparkleShare");
#endif
return new Configuration(config_path, "projects.xml");
});
private static readonly Lazy<Configuration> ConfigLazy = lazy;
Expand Down Expand Up @@ -71,9 +73,12 @@ public string FoldersPath
{
if (GetConfigOption("folders_path") != null)
return GetConfigOption("folders_path")!;
// TODO: Compiler switch
//return Path.Combine(HomePath, "SparkleShare");

#if DEBUG // TODO: rename compiler switch
return Path.Combine(HomePath, "SparkleShareDebug");
#else
return Path.Combine(HomePath, "SparkleShare");
#endif
}
}

Expand Down
12 changes: 7 additions & 5 deletions Sparkles/Git/Git.Fetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ protected override bool IsFetchedRepoEmpty {
public GitFetcher (SparkleFetcherInfo fetcher_info, SSHAuthenticationInfo auth_info) : base (fetcher_info)
{
this.auth_info = auth_info;
var uri_builder = new UriBuilder (RemoteUrl);

var uri_builder = new UriBuilder (RemoteUrl.ToUriString());
// TODO debug this section
if (!RemoteUrl.Scheme.Equals ("ssh") && !RemoteUrl.Scheme.Equals ("git"))
uri_builder.Scheme = "ssh";

Expand All @@ -63,8 +63,9 @@ public GitFetcher (SparkleFetcherInfo fetcher_info, SSHAuthenticationInfo auth_i
} else if (string.IsNullOrEmpty (RemoteUrl.UserInfo)) {
uri_builder.UserName = "storage";
}
bool tmp = RemoteUrl.scp_style;

RemoteUrl = uri_builder.Uri;
RemoteUrl = new ScpUri(uri_builder.Uri.ToString(),tmp);

AvailableStorageTypes.Add (
new StorageTypeInfo (StorageType.Encrypted, "Encrypted Storage",
Expand Down Expand Up @@ -307,11 +308,12 @@ public override string FormatName ()

StorageType? DetermineStorageType ()
{
// TODO bad hack, because ls-remote cant handle scp_like syntax
var git_ls_remote = new GitCommand (Configuration.DefaultConfiguration.TmpPath,
string.Format ("ls-remote --heads \"{0}\"", RemoteUrl), auth_info);
string.Format ("ls-remote --heads \"{0}\"", RemoteUrl.ToString()), auth_info);

string output = git_ls_remote.StartAndReadStandardOutput ();

// TODO handle exit codes 128,129,130 related to keys https://mazack.org/unix/errno.php
if (git_ls_remote.ExitCode != 0)
return null;

Expand Down
14 changes: 7 additions & 7 deletions Sparkles/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using System;
using System.IO;
using System.Xml.Schema;

namespace Sparkles
{
Expand Down Expand Up @@ -49,20 +50,17 @@ public static void LogInfo(string type, string message, Exception? exception)

if (Configuration.DebugMode)
Console.WriteLine(line);
StreamWriter log_writer = File.CreateText(Configuration.DefaultConfiguration.LogFilePath);
//lock (log_writer_lock)
{
try
{
log_writer.WriteLine(line);
log_writer.Flush();
log_writer.Close();

File.AppendAllLines(Configuration.DefaultConfiguration.LogFilePath, new List<string>([line]));
}

catch (Exception e)
{
Console.WriteLine(string.Format("Could not write to log {0}: {1} {2}",
(log_writer.BaseStream as FileStream)!.Name, e.Message, e.StackTrace));
Configuration.DefaultConfiguration.LogFilePath, e.Message, e.StackTrace));
}
}
}
Expand All @@ -72,13 +70,15 @@ public static void WriteCrashReport(Exception e)
{
/*if (log_writer != null)
log_writer.Close();*/

// TODO: get link to issues from static configuration
string crash_report_file_path= Configuration.DefaultConfiguration.CrashReportFilePath;
string n = Environment.NewLine;
string crash_report =
"Oops! SparkleShare has crashed... :(" + n +
n +
"If you want to help fix this crash, please report it at " + n +
"https://github.com/hbons/SparkleShare/issues and include the lines below." + n +
"https://github.com/uenz/SparkleShare/issues and include the lines below." + n +
n +
"Remove any sensitive information like file names, IP addresses, domain names, etc. if needed." + n +
n +
Expand Down
Loading

0 comments on commit 991c6e3

Please sign in to comment.