Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions FileSyncApp/FileSyncApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Serilog" Version="4.3.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
</ItemGroup>

Expand Down
8 changes: 8 additions & 0 deletions FileSyncApp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"FileSyncApp": {
"commandName": "Project",
"commandLineArgs": "Verbose"
}
}
}
2 changes: 2 additions & 0 deletions FileSyncApp/buildcommand.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dotnet publish -o pub-winx64 -c Release -p:PublishSingleFile=true -p:PublishTrimmed=false -p:Version=0.0.19-dev -r win-x64 --self-contained .\FileSyncApp.csproj
dotnet publish -o pub-linux64 -c Release -p:PublishSingleFile=true -p:PublishTrimmed=false -p:Version=0.0.19-dev -r linux-x64 --self-contained .\FileSyncApp.csproj
95 changes: 95 additions & 0 deletions FileSyncApp/genswu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

# Set variables
APP_VERSION="0.0.19-dev"
APP_NAME="FileSyncApp"
APP_DIR="/opt/$APP_NAME"
SERVICE_FILE="$APP_NAME.service"
SW_DESCRIPTION="sw-description"
OUTPUT_DIR="FileSyncAppPackage"
PUBLISH_DIR="publish"

dotnet publish -o $PUBLISH_DIR -c Release -p:PublishSingleFile=true -p:PublishTrimmed=false -p:Version=$APP_VERSION -r linux-x64 --self-contained ./FileSyncApp.csproj
# Create directory structure

mkdir -p ${OUTPUT_DIR}
mount -t ramfs ramfs ${OUTPUT_DIR}

# Create systemd service file
cat <<EOL > ${OUTPUT_DIR}/${SERVICE_FILE}
[Unit]
Description=FileSyncApp - Datei-Synchronisation
After=network.target

[Service]
ExecStart=$APP_DIR/$APP_NAME
WorkingDirectory=$APP_DIR
Restart=on-failure
User=root
Environment=DOTNET_EnableDiagnostics=0

[Install]
WantedBy=multi-user.target
EOL

# Create sw-description filex
cat <<EOL > ${OUTPUT_DIR}/${SW_DESCRIPTION}
software =
{
version = "$APP_VERSION";
description = "FileSyncApp Deployment";
bootloader_transaction_marker = false;
bootloader_state_marker = false;
hardware-compatibility: [ "#RE:.*" ];
files: (
{
filename = "$APP_NAME";
path = "$APP_DIR/$APP_NAME";
},
{
filename = "$APP_NAME.service";
path = "/etc/systemd/system/$SERVICE_FILE";
}
);
scripts: (
{
filename = "update.sh";
type = "shellscript";
}
);
preinstall = " || true && mkdir -p /opt/$APP_NAME";
postinstall = "systemctl daemon-reexec && systemctl daemon-reload && systemctl enable --now $APP_NAME.service";
};
EOL
cat <<\EOFUPDATE > ${OUTPUT_DIR}/update.sh
#!/bin/sh

if [ $# -lt 1 ]; then
exit 0;
fi
if [ $1 = "preinst" ]; then
systemctl stop FileSyncApp.service
mkdir -p /opt/FileSyncApp
echo "PREINST -> directory created"
fi

if [ $1 = "postinst" ]; then
chmod +x /opt/FileSyncApp/FileSyncApp
systemctl daemon-reexec
systemctl daemon-reload
systemctl enable --now FileSyncApp.service
fi

EOFUPDATE

# Copy the compiled binary to the package directory
cp ${PUBLISH_DIR}/$APP_NAME ${OUTPUT_DIR}

# Create CPIO archive
cd $OUTPUT_DIR
cpio -H crc -o < <(printf '%s\n' sw-description; find . ! -name sw-description -type f | sort) > ../$APP_NAME-$APP_VERSION.swu
cd ..
umount ${OUTPUT_DIR}
rm -r ${OUTPUT_DIR}

echo "SWUpdate package created: $APP_NAME-$APP_VERSION.swu"
4 changes: 2 additions & 2 deletions FileSyncAppConfigEditor/FileSyncAppConfigEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net10.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion FileSyncAppWin/FileSyncAppWin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net10.0-windows</TargetFramework>

<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
1 change: 1 addition & 0 deletions FileSyncAppWin/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal static class Program
[STAThread]
static void Main(string[] args)
{

_args = args;
FileSyncApp.Program.ConfigureLogger(args.FirstOrDefault());
logger = FileSyncApp.Program.LoggerFactory.CreateLogger("FileSyncAppWin");
Expand Down
8 changes: 8 additions & 0 deletions FileSyncAppWin/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"FileSyncAppWin": {
"commandName": "Project",
"commandLineArgs": "Verbose"
}
}
}
2 changes: 1 addition & 1 deletion FileSyncAppWin/buildcommand.cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dotnet publish -o pub -c Release -p:PublishSingleFile=true -p:PublishTrimmed=false -p:Version=0.0.16 -r win-x86 --self-contained .\FileSyncAppWin.csproj
dotnet publish -o pub -c Release -p:PublishSingleFile=true -p:PublishTrimmed=false -p:Version=0.0.20 -r win-x64 --self-contained .\FileSyncAppWin.csproj
29 changes: 26 additions & 3 deletions FileSyncLibNet/AccessProviders/FileIoAccessProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;

namespace FileSyncLibNet.AccessProviders
{
Expand All @@ -12,6 +13,9 @@ internal class FileIoAccessProvider : IAccessProvider
public string AccessPath { get; private set; }
private readonly RemoteState remoteState;
private readonly ILogger logger;
private const int DefaultBandwidthLimit = 100 * 1024 * 1024; // 100 MB/s
private int bandwidthLimit = DefaultBandwidthLimit;

public FileIoAccessProvider(ILogger logger, string stateFilename)
{
this.logger = logger;
Expand All @@ -38,7 +42,7 @@ public FileInfo2 GetFileInfo(string path)

return new FileInfo2(path, fi.Exists)
{
LastWriteTime = fi.Exists ? fi.LastWriteTime : DateTime.MinValue,
LastWriteTime = fi.Exists ? new DateTime(fi.LastWriteTime.Ticks) : DateTime.MinValue,
Length = fi.Exists ? fi.Length : 0
};
}
Expand Down Expand Up @@ -79,9 +83,28 @@ public void WriteFile(FileInfo2 file, Stream content)
{
var realFilename = Path.Combine(AccessPath, file.Name);
Directory.CreateDirectory(Path.GetDirectoryName(realFilename));
using (var stream = File.Create(realFilename))
if (bandwidthLimit == DefaultBandwidthLimit)
{
using (var stream = File.Create(realFilename))
{
content.CopyTo(stream);
}
}
else
{
content.CopyTo(stream);
using (var stream = new FileStream(realFilename, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.None))
{
int sleepIntervalMs = 50; // Fixed sleep interval
int bufferSize = bandwidthLimit / (1000 / sleepIntervalMs); // Calculate buffer size based on bandwidth limit and interval
byte[] buffer = new byte[bufferSize];
int bytesRead;

while ((bytesRead = content.Read(buffer, 0, buffer.Length)) > 0)
{
stream.Write(buffer, 0, bytesRead);
Thread.Sleep(sleepIntervalMs); // Sleep for the fixed interval
}
}
}
File.SetLastWriteTime(realFilename, file.LastWriteTime);
remoteState?.SetFileInfo(realFilename, file);
Expand Down
1 change: 1 addition & 0 deletions FileSyncLibNet/FileSyncJob/FileSyncJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private void RunJobInterlocked()
}
catch (Exception exc)
{
options.Logger.LogError(exc, "JobError {0}", JobName);
JobError?.Invoke(this, new FileSyncJobEventArgs(JobName, FileSyncJobStatus.Error, exc));
}
finally
Expand Down
8 changes: 4 additions & 4 deletions FileSyncLibNet/FileSyncLibNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
<Description>A library to easily backup or sync 2 folders either once or in a given interval.</Description>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.1" />
<PackageReference Include="RoboSharp" Version="1.6.0" />
<PackageReference Include="SMBLibrary" Version="1.5.4" />
<PackageReference Include="SSH.NET" Version="2024.2.0" />
<PackageReference Include="System.Text.Json" Version="9.0.1" />
<PackageReference Include="SMBLibrary" Version="1.5.5.1" />
<PackageReference Include="SSH.NET" Version="2025.1.0" />
<PackageReference Include="System.Text.Json" Version="10.0.1" />
</ItemGroup>
<ItemGroup>
<Content Include="../README.md">
Expand Down
Loading
Loading