Skip to content

Commit c585a8c

Browse files
Merge pull request #21 from andreaskueffel/development
update nuget packages, update target to net10, fix LastRun timestamp with subfolders
2 parents 8a35bae + b9a1982 commit c585a8c

16 files changed

Lines changed: 286 additions & 58 deletions

File tree

FileSyncApp/FileSyncApp.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
10-
<PackageReference Include="Serilog" Version="4.2.0" />
11-
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
9+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
10+
<PackageReference Include="Serilog" Version="4.3.0" />
11+
<PackageReference Include="Serilog.Extensions.Logging" Version="10.0.0" />
1212
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
13-
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
14-
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
13+
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
14+
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
1515
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
1616
</ItemGroup>
1717

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"FileSyncApp": {
4+
"commandName": "Project",
5+
"commandLineArgs": "Verbose"
6+
}
7+
}
8+
}

FileSyncApp/buildcommand.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
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
2+
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

FileSyncApp/genswu.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
# Set variables
4+
APP_VERSION="0.0.19-dev"
5+
APP_NAME="FileSyncApp"
6+
APP_DIR="/opt/$APP_NAME"
7+
SERVICE_FILE="$APP_NAME.service"
8+
SW_DESCRIPTION="sw-description"
9+
OUTPUT_DIR="FileSyncAppPackage"
10+
PUBLISH_DIR="publish"
11+
12+
dotnet publish -o $PUBLISH_DIR -c Release -p:PublishSingleFile=true -p:PublishTrimmed=false -p:Version=$APP_VERSION -r linux-x64 --self-contained ./FileSyncApp.csproj
13+
# Create directory structure
14+
15+
mkdir -p ${OUTPUT_DIR}
16+
mount -t ramfs ramfs ${OUTPUT_DIR}
17+
18+
# Create systemd service file
19+
cat <<EOL > ${OUTPUT_DIR}/${SERVICE_FILE}
20+
[Unit]
21+
Description=FileSyncApp - Datei-Synchronisation
22+
After=network.target
23+
24+
[Service]
25+
ExecStart=$APP_DIR/$APP_NAME
26+
WorkingDirectory=$APP_DIR
27+
Restart=on-failure
28+
User=root
29+
Environment=DOTNET_EnableDiagnostics=0
30+
31+
[Install]
32+
WantedBy=multi-user.target
33+
EOL
34+
35+
# Create sw-description filex
36+
cat <<EOL > ${OUTPUT_DIR}/${SW_DESCRIPTION}
37+
software =
38+
{
39+
version = "$APP_VERSION";
40+
description = "FileSyncApp Deployment";
41+
bootloader_transaction_marker = false;
42+
bootloader_state_marker = false;
43+
hardware-compatibility: [ "#RE:.*" ];
44+
files: (
45+
{
46+
filename = "$APP_NAME";
47+
path = "$APP_DIR/$APP_NAME";
48+
},
49+
{
50+
filename = "$APP_NAME.service";
51+
path = "/etc/systemd/system/$SERVICE_FILE";
52+
}
53+
);
54+
scripts: (
55+
{
56+
filename = "update.sh";
57+
type = "shellscript";
58+
}
59+
);
60+
preinstall = " || true && mkdir -p /opt/$APP_NAME";
61+
postinstall = "systemctl daemon-reexec && systemctl daemon-reload && systemctl enable --now $APP_NAME.service";
62+
};
63+
EOL
64+
cat <<\EOFUPDATE > ${OUTPUT_DIR}/update.sh
65+
#!/bin/sh
66+
67+
if [ $# -lt 1 ]; then
68+
exit 0;
69+
fi
70+
if [ $1 = "preinst" ]; then
71+
systemctl stop FileSyncApp.service
72+
mkdir -p /opt/FileSyncApp
73+
echo "PREINST -> directory created"
74+
fi
75+
76+
if [ $1 = "postinst" ]; then
77+
chmod +x /opt/FileSyncApp/FileSyncApp
78+
systemctl daemon-reexec
79+
systemctl daemon-reload
80+
systemctl enable --now FileSyncApp.service
81+
fi
82+
83+
EOFUPDATE
84+
85+
# Copy the compiled binary to the package directory
86+
cp ${PUBLISH_DIR}/$APP_NAME ${OUTPUT_DIR}
87+
88+
# Create CPIO archive
89+
cd $OUTPUT_DIR
90+
cpio -H crc -o < <(printf '%s\n' sw-description; find . ! -name sw-description -type f | sort) > ../$APP_NAME-$APP_VERSION.swu
91+
cd ..
92+
umount ${OUTPUT_DIR}
93+
rm -r ${OUTPUT_DIR}
94+
95+
echo "SWUpdate package created: $APP_NAME-$APP_VERSION.swu"

FileSyncAppConfigEditor/FileSyncAppConfigEditor.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net8.0-windows</TargetFramework>
5+
<TargetFramework>net10.0-windows</TargetFramework>
66
<Nullable>enable</Nullable>
77
<UseWindowsForms>true</UseWindowsForms>
88
<ImplicitUsings>enable</ImplicitUsings>
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
12+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

FileSyncAppWin/FileSyncAppWin.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net8.0-windows</TargetFramework>
5+
<TargetFramework>net10.0-windows</TargetFramework>
66

77
<UseWindowsForms>true</UseWindowsForms>
88
<ImplicitUsings>enable</ImplicitUsings>

FileSyncAppWin/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ internal static class Program
2020
[STAThread]
2121
static void Main(string[] args)
2222
{
23+
2324
_args = args;
2425
FileSyncApp.Program.ConfigureLogger(args.FirstOrDefault());
2526
logger = FileSyncApp.Program.LoggerFactory.CreateLogger("FileSyncAppWin");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"FileSyncAppWin": {
4+
"commandName": "Project",
5+
"commandLineArgs": "Verbose"
6+
}
7+
}
8+
}

FileSyncAppWin/buildcommand.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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
1+
dotnet publish -o pub -c Release -p:PublishSingleFile=true -p:PublishTrimmed=false -p:Version=0.0.20 -r win-x64 --self-contained .\FileSyncAppWin.csproj

FileSyncLibNet/AccessProviders/FileIoAccessProvider.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Linq;
7+
using System.Threading;
78

89
namespace FileSyncLibNet.AccessProviders
910
{
@@ -12,6 +13,9 @@ internal class FileIoAccessProvider : IAccessProvider
1213
public string AccessPath { get; private set; }
1314
private readonly RemoteState remoteState;
1415
private readonly ILogger logger;
16+
private const int DefaultBandwidthLimit = 100 * 1024 * 1024; // 100 MB/s
17+
private int bandwidthLimit = DefaultBandwidthLimit;
18+
1519
public FileIoAccessProvider(ILogger logger, string stateFilename)
1620
{
1721
this.logger = logger;
@@ -38,7 +42,7 @@ public FileInfo2 GetFileInfo(string path)
3842

3943
return new FileInfo2(path, fi.Exists)
4044
{
41-
LastWriteTime = fi.Exists ? fi.LastWriteTime : DateTime.MinValue,
45+
LastWriteTime = fi.Exists ? new DateTime(fi.LastWriteTime.Ticks) : DateTime.MinValue,
4246
Length = fi.Exists ? fi.Length : 0
4347
};
4448
}
@@ -79,9 +83,28 @@ public void WriteFile(FileInfo2 file, Stream content)
7983
{
8084
var realFilename = Path.Combine(AccessPath, file.Name);
8185
Directory.CreateDirectory(Path.GetDirectoryName(realFilename));
82-
using (var stream = File.Create(realFilename))
86+
if (bandwidthLimit == DefaultBandwidthLimit)
87+
{
88+
using (var stream = File.Create(realFilename))
89+
{
90+
content.CopyTo(stream);
91+
}
92+
}
93+
else
8394
{
84-
content.CopyTo(stream);
95+
using (var stream = new FileStream(realFilename, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.None))
96+
{
97+
int sleepIntervalMs = 50; // Fixed sleep interval
98+
int bufferSize = bandwidthLimit / (1000 / sleepIntervalMs); // Calculate buffer size based on bandwidth limit and interval
99+
byte[] buffer = new byte[bufferSize];
100+
int bytesRead;
101+
102+
while ((bytesRead = content.Read(buffer, 0, buffer.Length)) > 0)
103+
{
104+
stream.Write(buffer, 0, bytesRead);
105+
Thread.Sleep(sleepIntervalMs); // Sleep for the fixed interval
106+
}
107+
}
85108
}
86109
File.SetLastWriteTime(realFilename, file.LastWriteTime);
87110
remoteState?.SetFileInfo(realFilename, file);

0 commit comments

Comments
 (0)