mirror of
https://github.com/winsw/winsw.git
synced 2025-12-10 18:37:28 +08:00
Support merging plugins into winsw.exe executable
* Decouple Core components into WinSWCore projects. * Use ILMerge to merge everything (inc. Plugins) into a single executable TODO: API Should be refactored before the publishing TODO: check signing procedure Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com> Conflicts: src/Core/ServiceWrapper/winsw.csproj Conflicts: src/Core/ServiceWrapper/Main.cs src/winsw.sln
This commit is contained in:
48
src/Core/WinSWCore/Download.cs
Executable file
48
src/Core/WinSWCore/Download.cs
Executable file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Xml;
|
||||
|
||||
namespace winsw
|
||||
{
|
||||
/// <summary>
|
||||
/// Specify the download activities prior to the launch.
|
||||
/// This enables self-updating services.
|
||||
/// </summary>
|
||||
public class Download
|
||||
{
|
||||
public readonly string From;
|
||||
public readonly string To;
|
||||
|
||||
internal Download(XmlNode n)
|
||||
{
|
||||
From = Environment.ExpandEnvironmentVariables(n.Attributes["from"].Value);
|
||||
To = Environment.ExpandEnvironmentVariables(n.Attributes["to"].Value);
|
||||
}
|
||||
|
||||
public void Perform()
|
||||
{
|
||||
WebRequest req = WebRequest.Create(From);
|
||||
WebResponse rsp = req.GetResponse();
|
||||
FileStream tmpstream = new FileStream(To + ".tmp", FileMode.Create);
|
||||
CopyStream(rsp.GetResponseStream(), tmpstream);
|
||||
// only after we successfully downloaded a file, overwrite the existing one
|
||||
if (File.Exists(To))
|
||||
File.Delete(To);
|
||||
File.Move(To + ".tmp", To);
|
||||
}
|
||||
|
||||
private static void CopyStream(Stream i, Stream o)
|
||||
{
|
||||
byte[] buf = new byte[8192];
|
||||
while (true)
|
||||
{
|
||||
int len = i.Read(buf, 0, buf.Length);
|
||||
if (len <= 0) break;
|
||||
o.Write(buf, 0, len);
|
||||
}
|
||||
i.Close();
|
||||
o.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user