You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.3 KiB
71 lines
2.3 KiB
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Threading;
|
|
|
|
namespace IoTDameon.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly IWebHostEnvironment _env;
|
|
|
|
public HomeController(IWebHostEnvironment env)
|
|
{
|
|
this._env = env;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
var path = Path.Combine(this._env.WebRootPath, "upload");
|
|
return View(model: path);
|
|
}
|
|
|
|
public IActionResult GetVersion()
|
|
{
|
|
return Content(Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion);
|
|
}
|
|
|
|
private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public IActionResult Upload()
|
|
{
|
|
if (Request.Form.Files != null && Request.Form.Files.Count > 0)
|
|
{
|
|
var file = Request.Form.Files[0];
|
|
using Stream stream = file.OpenReadStream();
|
|
var phicyPath = Path.Combine(this._env.WebRootPath, "upload");
|
|
Directory.CreateDirectory(phicyPath);
|
|
var name = file.FileName;
|
|
var fullName = Path.Combine(phicyPath, name);
|
|
if (System.IO.File.Exists(fullName))
|
|
{
|
|
System.IO.File.Delete(fullName);
|
|
}
|
|
using (FileStream fs = System.IO.File.Create(fullName))
|
|
{
|
|
file.CopyTo(fs);
|
|
}
|
|
var ext = Path.GetExtension(fullName);
|
|
if (ext == "zip")
|
|
{
|
|
var zipDirectory = Path.Combine(phicyPath, Path.GetFileName(fullName));
|
|
if (!Directory.Exists(zipDirectory))
|
|
{
|
|
Directory.CreateDirectory(zipDirectory);
|
|
}
|
|
ZipFile.ExtractToDirectory(fullName, zipDirectory);
|
|
}
|
|
}
|
|
return RedirectToAction("Index");
|
|
}
|
|
}
|
|
} |