public string CheckJava(string binaryName) { var javapath = Path.Combine(RuntimeDirectory, "bin", binaryName); if (!File.Exists(javapath)) { string json = ""; var javaUrl = ""; using (var wc = new WebClient()) { //this line was added if (MRule.OSName == MRule.Linux) { return("java"); } json = wc.DownloadString(MojangServer.LauncherMeta); var job = JObject.Parse(json)[MRule.OSName]; javaUrl = job[MRule.Arch]?["jre"]?["url"]?.ToString(); if (string.IsNullOrEmpty(javaUrl)) { throw new PlatformNotSupportedException("Downloading JRE on current OS is not supported. Set JavaPath manually."); } Directory.CreateDirectory(RuntimeDirectory); } var lzmapath = Path.Combine(Path.GetTempPath(), "jre.lzma"); var zippath = Path.Combine(Path.GetTempPath(), "jre.zip"); var webdownloader = new WebDownload(); webdownloader.DownloadProgressChangedEvent += Downloader_DownloadProgressChangedEvent; webdownloader.DownloadFile(javaUrl, lzmapath); DownloadCompleted?.Invoke(this, new EventArgs()); SevenZipWrapper.DecompressFileLZMA(lzmapath, zippath); var z = new SharpZip(zippath); z.ProgressEvent += Z_ProgressEvent; z.Unzip(RuntimeDirectory); if (!File.Exists(javapath)) { throw new Exception("Failed Download"); } if (MRule.OSName != MRule.Windows) { IOUtil.Chmod(javapath, IOUtil.Chmod755); } } return(javapath); }
public ActionResult ZipFile(string systemName) { var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName(systemName, LoadPluginsMode.All); if (pluginDescriptor == null) { //No plugin found with the specified id return(ErrorNotification("plugin not found!")); } var strPath = string.Format("{0}\\Plugins\\{1}", Request.PhysicalApplicationPath, pluginDescriptor.SystemName); if (!Directory.Exists(Request.PhysicalApplicationPath + "Temp")) { Directory.CreateDirectory(Request.PhysicalApplicationPath + "Temp"); } var strPathTemp = string.Format("{0}\\Temp\\{1}.zip", Request.PhysicalApplicationPath, Guid.NewGuid()); // ZipOutputStream ms = new ZipOutputStream(a); SharpZip.PackFiles(strPathTemp, strPath, @"-\.cs$;-\.csproj$;-\.user$;-\\obj\\;-\\Properties\\;"); // ms.Position = 0; // ms.Flush(); return(File(strPathTemp, "application/x-zip-compressed", pluginDescriptor.SystemName + ".zip")); }
private void GetResponseCallback(IAsyncResult asynchronousResult) { RequestState requestState = (RequestState)asynchronousResult.AsyncState; HttpWebRequest request = requestState.Request;//(HttpWebRequest)asynchronousResult.AsyncState; using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult)) using (Stream stream = response.GetResponseStream()) using (StreamReader streamReader = new StreamReader(stream)) { string responseString = streamReader.ReadToEnd(); string responseData = ""; try { responseData = SharpZip.StringZipToString(responseString); } catch (Exception exception) { //Convert Error requestState.ErrorCallback(Convert.ToInt32(RestApiConfig.ResponseTypes.CONVERT_FAILED), exception.Message); } // Close the stream object stream.Close(); streamReader.Close(); // Release the HttpWebResponse response.Close(); allDone.Set(); isSuccess = true; Abort(); //Callback requestState.ResponseCallback(requestState.SendString, responseData); } }
private int ExtractApplicationPackage(Application app, string tenantName) { try { string filePath = Path.Combine(Settings.ApplicationStorePath, app.FileName); if (!MonoscapeUtil.WebConfigExistsInRoot(filePath)) { throw new MonoscapeException("Application package is not valid. Re-package the application without any folders and try again."); } int port = (Database.LastWebServerPort + 1); string extractPath = PrepareApplicationDeployPath(app, tenantName, port); if (Directory.Exists(extractPath)) { // Remove previously extracted application content Directory.Delete(extractPath, true); Directory.CreateDirectory(extractPath); } else if (!Directory.Exists(Settings.ApplicationDeployPath)) { // Create application deployment path Directory.CreateDirectory(Settings.ApplicationDeployPath); } SharpZip.Extract(extractPath, filePath); return(port); } catch (Exception e) { throw new MonoscapeException("Application package extraction failed", e); } }
public string ExtractNatives() { string path = gamePath.GetNativePath(version.Id); Directory.CreateDirectory(path); if (version.Libraries == null) { return(path); } foreach (var item in version.Libraries) { try { if (item.IsRequire && item.IsNative && !string.IsNullOrEmpty(item.Path)) { string zPath = Path.Combine(gamePath.Library, item.Path); if (File.Exists(zPath)) { var z = new SharpZip(zPath); z.Unzip(path); } } } catch { // ignore invalid native library file } } return(path); }
public string CheckJava(string binaryName) { var javapath = Path.Combine(RuntimeDirectory, "bin", binaryName); if (!File.Exists(javapath)) { string json = ""; var WorkingPath = Path.Combine(Path.GetTempPath(), "temp_download_runtime"); if (Directory.Exists(WorkingPath)) { IOUtil.DeleteDirectory(WorkingPath); } Directory.CreateDirectory(WorkingPath); var javaUrl = ""; using (var wc = new WebClient()) { json = wc.DownloadString(MojangServer.LauncherMeta); var job = JObject.Parse(json)[MRule.OSName]; javaUrl = job[MRule.Arch]?["jre"]?["url"]?.ToString(); if (string.IsNullOrEmpty(javaUrl)) { throw new Exception("unsupport os"); } Directory.CreateDirectory(RuntimeDirectory); } var downloader = new WebDownload(); downloader.DownloadProgressChangedEvent += Downloader_DownloadProgressChangedEvent; downloader.DownloadFile(javaUrl, Path.Combine(WorkingPath, "javatemp.lzma")); var lzma = Path.Combine(WorkingPath, "javatemp.lzma"); var zip = Path.Combine(WorkingPath, "javatemp.zip"); SevenZipWrapper.DecompressFileLZMA(lzma, zip); var z = new SharpZip(zip); z.Unzip(RuntimeDirectory); if (!File.Exists(javapath)) { IOUtil.DeleteDirectory(WorkingPath); throw new Exception("Failed Download"); } if (MRule.OSName != "windows") { IOUtil.Chmod(javapath, IOUtil.Chmod755); } DownloadCompleted?.Invoke(this, new EventArgs()); } return(javapath); }
/// <summary> /// 文件下载 /// </summary> /// <returns></returns> private void Down(HttpContext context) { ZipHelper zip = new ZipHelper(); JsonModel jsonModel = null; JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer(); string ids = context.Request.Form["DownID"].SafeToString(); string ZipUrl = context.Server.MapPath(ConfigHelper.GetConfigString("ZipUrl")) + "/" + DateTime.Now.Ticks; string DownUrl = ConfigHelper.GetConfigString("DownUrl"); string result = "0"; try { string[] idarry = ids.TrimEnd(',').Split(','); FileHelper.CreateDirectory(ZipUrl); for (int i = 0; i < idarry.Length; i++) { #region 文件移动 JsonModel model = Bll.GetEntityById(int.Parse(idarry[i])); MyResource resource = (MyResource)(model.retData); string FileUrl = resource.FileUrl; if (resource.postfix == "") { FileHelper.CopyFolder(context.Server.MapPath(FileUrl), ZipUrl); } else { FileHelper.CopyTo(context.Server.MapPath(FileUrl), ZipUrl + FileUrl.Substring(FileUrl.LastIndexOf("/"))); } #endregion } string ZipName = "/下载文件" + DateTime.Now.Ticks + ".rar"; //文件打包 SharpZip.PackFiles(context.Server.MapPath(ConfigHelper.GetConfigString("ZipUrl")) + ZipName, ZipUrl); jsonModel = new JsonModel() { errNum = 0, errMsg = "", retData = DownUrl + "\\" + ZipName //+ ".rar" }; } catch (Exception ex) { jsonModel = new JsonModel() { errNum = 400, errMsg = ex.Message, retData = "" }; LogService.WriteErrorLog(ex.Message); } result = "{\"result\":" + jss.Serialize(jsonModel) + "}"; context.Response.Write(result); context.Response.End(); }
private void timer_Tick(object sender, EventArgs e) { this.timer.Enabled = false; MessageBox.Show(jo["fileurl"].ToString()); DownloadFile(jo["fileurl"].ToString(), @"C:\tale.zip", progressBar1, label2); Tools.DeleteFile(@"C:\TaleBlog\tale"); SharpZip.UnZip(@"C:\\tale.zip", @"C:\TaleBlog"); MessageBox.Show("更新成功!请重启软件!请使用请客户端启动程序!!客户端路径为C:\\TaleBlog\\tale\\tale.exe", "提示"); }
private void decompressJavaFile(string lzmaPath) { string zippath = Path.Combine(Path.GetTempPath(), "jre.zip"); SevenZipWrapper.DecompressFileLZMA(lzmaPath, zippath); var z = new SharpZip(zippath); z.ProgressEvent += Z_ProgressEvent; z.Unzip(RuntimeDirectory); }
private void timer_Tick(object sender, EventArgs e) { this.timer.Enabled = false; string txtContent = GetVersion("https://raw.githubusercontent.com/coding1618/TaleWindowUpData/master/updata.json"); JObject jo = (JObject)JsonConvert.DeserializeObject(txtContent); DownloadFile(jo["fileurl"].ToString(), @"C:\tale.zip", progressBar1); Set_OS_Path.SetSysEnvironment("TaleHome", @"C:\TaleBlog"); MessageBox.Show("安装成功请重启,请使用桌面快捷方式启动,本文件请保留!请点击X退出重启软件!", "提示:"); SharpZip.UnZip(@"C:\\tale.zip", @"C:\TaleBlog"); Application.Exit(); }
public bool CompressPackage(string directory) { bool bRet = true; if (string.IsNullOrEmpty(directory)) { return(false); } directory = directory.Replace("/", "\\"); bRet = SharpZip.CompressDirectory(directory, directory + ".zip", true); return(bRet); }
private void RequestStreamCallback(IAsyncResult asyncResult) { RequestState requestState = (RequestState)asyncResult.AsyncState; using (Stream stream = requestState.Request.EndGetRequestStream(asyncResult)) { string postData = SharpZip.StringToStringZip(requestState.SendString); byte[] byteArray = Encoding.UTF8.GetBytes(postData); stream.Write(byteArray, 0, postData.Length); stream.Close(); requestState.Request.BeginGetResponse(new AsyncCallback(GetResponseCallback), requestState); } }
private void ExtractNatives(MProfile profile, string path) { Directory.CreateDirectory(path); foreach (var item in profile.Libraries) { try { if (item.IsNative) { var z = new SharpZip(item.Path); z.Unzip(path); } } catch { } } profile.NativePath = path; }
/// <summary> /// 下载所有日志 /// </summary> /// <param name="FilePath">文件路径</param> /// <param name="s">文件输出流</param> /// <param name="list">要导出的文件路径集合</param> public static void DowloadLog(string FilePath, List <string> list, Stream s) { string desc = FileHelper.GetAbsolutePath(Guid.NewGuid().ToString("N")); FileHelper.CopyFiles(list, desc); SharpZip.PackFiles(FileHelper.GetAbsolutePath(FilePath), desc); Directory.Delete(desc, true); byte[] m_buffer = new byte[BUFFER_SIZE]; int count = 0; using (FileStream fs = File.OpenRead(FilePath)) { do { count = fs.Read(m_buffer, 0, BUFFER_SIZE); s.Write(m_buffer, 0, count); } while (count == BUFFER_SIZE); } File.Delete(FilePath); }
public string ExtractNatives() { var path = gamePath.GetNativePath(version.Id); Directory.CreateDirectory(path); foreach (var item in version.Libraries) { try { if (item.IsRequire && item.IsNative) { var z = new SharpZip(Path.Combine(gamePath.Library, item.Path)); z.Unzip(path); } } catch { } } return(path); }
private DownloadFile[] legacyJavaChecker(MinecraftPath path, out string binPath) { string legacyJavaPath = Path.Combine(path.Runtime, "m-legacy"); MJava mJava = new MJava(legacyJavaPath); binPath = mJava.GetBinaryPath(); if (mJava.CheckJavaExistence()) { return new DownloadFile[] {} } ; string javaUrl = mJava.GetJavaUrl(); string lzmaPath = Path.Combine(Path.GetTempPath(), "jre.lzma"); string zipPath = Path.Combine(Path.GetTempPath(), "jre.zip"); DownloadFile file = new DownloadFile(lzmaPath, javaUrl) { Name = "jre.lzma", Type = MFile.Runtime, AfterDownload = new Func <Task>[] { () => Task.Run(() => { SevenZipWrapper.DecompressFileLZMA(lzmaPath, zipPath); var z = new SharpZip(zipPath); z.Unzip(legacyJavaPath); tryChmod755(mJava.GetBinaryPath()); }) } }; return(new[] { file }); }
public string CheckJava(string binaryName) { var javapath = Path.Combine(RuntimeDirectory, "bin", binaryName); if (File.Exists(javapath)) { return(javapath); } string json = ""; var javaUrl = ""; using (var wc = new WebClient()) { json = wc.DownloadString(MojangServer.LauncherMeta); var job = JObject.Parse(json)[MRule.OSName]; javaUrl = job[MRule.Arch]?["jre"]?["url"]?.ToString(); Log.Information("Downloading java from: " + javaUrl); if (string.IsNullOrEmpty(javaUrl)) { Log.Error("Downloading JRE on current OS is not supported. Set JavaPath manually."); throw new PlatformNotSupportedException("Downloading JRE on current OS is not supported. Set JavaPath manually."); } Directory.CreateDirectory(RuntimeDirectory); } var lzmapath = Path.Combine(Path.GetTempPath(), "jre.lzma"); var zippath = Path.Combine(Path.GetTempPath(), "jre.zip"); Log.Information($"Downloading to: {lzmapath}"); var webdownloader = new WebDownload(); webdownloader.DownloadProgressChangedEvent += Downloader_DownloadProgressChangedEvent; webdownloader.DownloadFile(javaUrl, lzmapath); DownloadCompleted?.Invoke(this, new EventArgs()); Log.Information("Download completed. Start LZMAing..."); try { SevenZipWrapper.DecompressFileLZMA(lzmapath, zippath); //SevenZipWrapper.DecompressFileLZMA(lzmapath, zippath); } catch (Exception e) { Log.Error(e, "LZMA Error"); } Log.Information("Start Unzipping..."); var z = new SharpZip(zippath); z.ProgressEvent += Z_ProgressEvent; z.Unzip(RuntimeDirectory); if (!File.Exists(javapath)) { Log.Error("Failed Download Java File exists: " + javapath); throw new Exception("Failed Download"); } if (MRule.OSName != "windows") { IOUtil.Chmod(javapath, IOUtil.Chmod755); } Log.Information("Java path: " + javapath); return(javapath); }
public WorkerResult Update() { var h = Curl.GetHtmlAsync(Settings.baseHref + addon.href); if (null == h) { Settings.LogException(GenMsg("抓取远程内容失败!插件更新退出")); return(result); } var cdl = Curse.PraseDownload(h); if (null == cdl || string.IsNullOrEmpty(cdl.version) || string.IsNullOrEmpty(cdl.href)) { Settings.LogException(new Exception(GenMsg("无法获取插件最新版本,可能解析错误!插件更新退出"))); return(result); } if (!string.IsNullOrEmpty(addon.local_version) && cdl.version.Equals(addon.local_version)) { Settings.Log(GenMsg("插件已经最新,插件更新退出")); return(result); } string cachePath; try { cachePath = Path.Combine(Settings.sc.cachePath, addon.addon_id); if (!Directory.Exists(cachePath)) { Directory.CreateDirectory(cachePath); } } catch (Exception e) { Settings.LogException(e); return(result); } string localFile = string.Format(@"{0}\{1}\{2}", Settings.sc.cachePath, addon.addon_id, cdl.version); string tmp = localFile + ".tmp"; string tar = localFile + ".zip"; if (File.Exists(tar)) { Settings.Log(GenMsg("该插件已有本地缓存跳过下载")); } else { if (Curl.Download(Settings.baseHref + cdl.href, tmp)) { Settings.Log(GenMsg("插件包下载成功")); File.Move(tmp, tar); } else { Settings.LogException(new Exception(GenMsg("下载最新版本失败!插件更新退出"))); return(result); } } string addonPath = ""; try { addonPath = Path.Combine(Settings.sc.game_path, Settings.addonPath); if (!Directory.Exists(addonPath)) { Directory.CreateDirectory(addonPath); Settings.Log(GenMsg("游戏插件目录不存在,创建成功")); } } catch { Settings.LogException(new Exception(GenMsg("创建游戏插件目录失败!插件更新退出:" + addonPath))); return(result); } try { //安装结果是顶级路径,便于卸载时删除,返回null说明安装失败 var installResult = SharpZip.DecomparessFile(tar, addonPath); if (null != installResult) { addon.local_version = cdl.version; addon.update_time = DateTime.Now.ToString(); addon.file_paths = installResult; Settings.db.UpdateAddon(addon); Settings.Xlog.Add(GenMsg(" 插件更新成功,最新版本[" + cdl.version + "]"), "插件更新", XLog.AsyncLogLevel.INFO); result.success = true; return(result); } else { Settings.LogException(new Exception(GenMsg("插件安装失败,尝试接解压到插件目录出错;" + addonPath))); return(result); } }catch (Exception e) { Settings.LogException(e); GenMsg("插件安装失败!"); return(result); } }
public void InitPdone() { setting = GetUserData(); Application.ApplicationExit += (sender, e) => { SetUserData(setting); }; this.FormClosed += (sender, e) => { if (AdbProcessInfo != null) { //退出前关闭adb AdbProcessInfo.Arguments = "kill-server"; Process.Start(AdbProcessInfo); LogHelper.Info("kill adb server"); } Application.Exit(); }; #region 设置标题 Assembly asm = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location); ledTitle.Text = $"Free Control v{fvi.ProductVersion}"; ledTitle.CharCount = 19; ledTitle.MouseDown += (sender, e) => DragWindow(); this.Icon = Properties.Resources.pcm; #endregion #region 设置主题颜色 UIStyles.SetStyle(UIStyle.Gray); //设置默认导航条颜色 navTab.TabSelectedForeColor = Color.FromArgb(140, 140, 140); navTab.TabSelectedHighColor = Color.FromArgb(140, 140, 140); //设置默认导航条图标 tabHome.ImageIndex = 0; tabSetting.ImageIndex = 2; #endregion #region 设置深色模式 switchDarkMode.ValueChanged += (object sender, bool value) => { var tabBackColor = Color.Transparent; if (value) { tabBackColor = Color.FromArgb(24, 24, 24); UIStyles.SetStyle(UIStyle.Black); tabHome.BackColor = tabBackColor; tabSetting.BackColor = tabBackColor; navTab.MenuStyle = UIMenuStyle.Black; btnStart.SetStyle(UIStyle.Black); tabHome.ImageIndex = 1; tabSetting.ImageIndex = 3; } else { tabBackColor = Color.FromArgb(242, 242, 244); UIStyles.SetStyle(UIStyle.Gray); tabHome.BackColor = tabBackColor; tabSetting.BackColor = tabBackColor; navTab.MenuStyle = UIMenuStyle.White; btnStart.SetStyle(UIStyle.Gray); tabHome.ImageIndex = 0; tabSetting.ImageIndex = 2; navTab.TabSelectedForeColor = Color.FromArgb(140, 140, 140); navTab.TabSelectedHighColor = Color.FromArgb(140, 140, 140); } }; #endregion #region 切换tab事件 navTab.SelectedIndexChanged += (object sender, EventArgs e) => { }; navTab.SelectTab(0); #endregion #region 设置默认值 rbtnPx.SelectedIndex = setting.PXIndex; rbtnMbps.SelectedIndex = setting.BitRateIndex; rbtnMaxFPS.SelectedIndex = setting.MaxFPSIndex; switchDarkMode.Active = setting.DarkMode; tbxAddress.Text = setting.IPAddress; tbxPort.Text = setting.Port; tbxAddress.Enabled = !setting.UseWireless; tbxPort.Enabled = !setting.UseWireless; #region 框默认值 cbxUseWireless.Checked = setting.UseWireless; cbxUseLog.Checked = setting.UseLog; LogHelper.enable = setting.UseLog; cbxCloseScreen.Checked = setting.CloseScreen; cbxKeepAwake.Checked = setting.KeepAwake; cbxAllFPS.Checked = setting.AllFPS; cbxHideBorder.Checked = setting.HideBorder; cbxFullScreen.Checked = setting.FullScreen; cbxTopMost.Checked = setting.TopMost; #endregion #region 参数设置事件 rbtnPx.ValueChanged += RbtnPx_ValueChanged; rbtnMbps.ValueChanged += RbtnMbps_ValueChanged; rbtnMaxFPS.ValueChanged += RbtnMaxFPS_ValueChanged; cbxUseWireless.ValueChanged += CbxUseWireless_ValueChanged; cbxUseLog.ValueChanged += CbxUseLog_ValueChanged;; switchDarkMode.ValueChanged += (sender, e) => { setting.DarkMode = switchDarkMode.Active; }; tbxAddress.TextChanged += TbxAddress_TextChanged; tbxPort.TextChanged += TbxPort_TextChanged; cbxCloseScreen.ValueChanged += CommonCbx_ValueChanged; cbxKeepAwake.ValueChanged += CommonCbx_ValueChanged; cbxAllFPS.ValueChanged += CommonCbx_ValueChanged; cbxHideBorder.ValueChanged += CommonCbx_ValueChanged; cbxFullScreen.ValueChanged += CommonCbx_ValueChanged; cbxTopMost.ValueChanged += CommonCbx_ValueChanged; #endregion #endregion #region 启动前 string tempFileName = "temp.zip"; if (!Directory.Exists(scrcpyPath)) { Directory.CreateDirectory(scrcpyPath); File.WriteAllBytes(scrcpyPath + tempFileName, Properties.Resources.scrcpy_win32_v1_17); if (SharpZip.UnpackFiles(scrcpyPath + tempFileName, scrcpyPath)) { File.Delete(scrcpyPath + tempFileName); } } #endregion Process scrcpy = null; //设置端口号命令 adb tcpip 5555 #region 启动按钮 btnStart.Click += (sender, e) => { if (setting.UseWireless && (string.IsNullOrWhiteSpace(setting.IPAddress) || string.IsNullOrWhiteSpace(setting.Port))) { UIMessageTip.ShowWarning(sender as Control, "IP地址或者端口号没有填写,无法启动 -.-!", 1500); return; } LogHelper.Info("starting..."); var paramlist = $" {setting.BitRate} {setting.PX} {setting.MaxFPS} {setting.OtherParam} "; //设置屏幕高度 800 paramlist += "--window-height 800 "; //设置快捷键 左Crtl paramlist += "--shortcut-mod=lctrl "; //设置标题 paramlist += $"--window-title \"{ledTitle.Text}\" "; AdbProcessInfo = new ProcessStartInfo($@"{scrcpyPath}adb.exe", $"connect {setting.IPAddress}:{setting.Port}") { CreateNoWindow = true, //设置不在新窗口中启动新的进程 UseShellExecute = false, //不使用操作系统使用的shell启动进程 RedirectStandardOutput = true, //将输出信息重定向 }; if (setting.UseWireless) { //启动ABD Process adb = Process.Start(AdbProcessInfo); LogHelper.Info(adb.StandardOutput.ReadToEnd()); adb.WaitForExit(); paramlist = $"-s {setting.IPAddress}:{setting.Port} " + paramlist; } scrcpy = Process.Start(new ProcessStartInfo($@"{scrcpyPath}scrcpy.exe", paramlist) { CreateNoWindow = true, //设置不在新窗口中启动新的进程 UseShellExecute = false, //不使用操作系统使用的shell启动进程 RedirectStandardOutput = true, //将输出信息重定向 }); this.Hide(); LogHelper.Info("scrcpy running..."); LogHelper.Info(scrcpy.StandardOutput.ReadToEnd()); scrcpy.WaitForExit(); UIMessageTip.Show(this, "已退出", null, 1500); this.Show(); }; #endregion }
/// <summary> /// 上传plugin zip文件 /// </summary> /// <returns></returns> public ActionResult PostFile(string systemName) { string strErrorMsg = ""; string strName = ""; try { string strPath = ""; if (Request.Files.Count > 0) { if (!System.IO.Directory.Exists(string.Format("{0}\\temp", Request.PhysicalApplicationPath))) { System.IO.Directory.CreateDirectory(string.Format("{0}\\temp", Request.PhysicalApplicationPath)); } if (!System.IO.Directory.Exists(string.Format("{0}\\BackUp", Request.PhysicalApplicationPath))) { System.IO.Directory.CreateDirectory(string.Format("{0}\\BackUp", Request.PhysicalApplicationPath)); } HttpPostedFileBase objFile = Request.Files[0]; var pad = DateTime.Now.ToString("yyyyMMddHHmmss"); strPath = string.Format("{0}\\temp\\{1}{2}", Request.PhysicalApplicationPath, pad, System.IO.Path.GetExtension(objFile.FileName)); // dic.Add(objFile.FileName, objFile.InputStream); objFile.SaveAs(strPath); //System.IO.MemoryStream stream = new System.IO.MemoryStream(objZip.ZipContent); SharpZip.UnpackFiles(strPath, string.Format("{0}temp\\{1}\\", Request.PhysicalApplicationPath, pad)); var strPathTemp = strPath.Replace(System.IO.Path.GetExtension(objFile.FileName), "\\"); var bolCheck = CheckModule(objFile.FileName, strPathTemp); PluginDescriptor plugTemp = null; if (bolCheck) { plugTemp = PluginFileParser.ParsePluginDescriptionFile(strPathTemp + "\\Description.txt"); if (!string.IsNullOrEmpty(systemName) && systemName != "0" && plugTemp.SystemName != systemName) { throw new Exception("System Name不对,插件不兼容!"); } if (!string.IsNullOrEmpty(systemName) && systemName != "0") //编辑时先删除以前的 { var plugTemp1 = ((List <PluginDescriptor>)PluginManager.AllPlugins) .Find(a => a.SystemName == plugTemp.SystemName); // 如果前后名字对不上,不能装啊 if (plugTemp1 == null) { // 对不上了,看systemName,如果空的话就是添加,否则不让操作 if (!string.IsNullOrEmpty(systemName)) { throw new Exception("System Name不对,插件不兼容!"); } } } else { //是否存在相同的 // plugTemp = PluginManager.GetPluginDescriptor(new DirectoryInfo(System.IO.Path.GetDirectoryName(strPath))); if (((List <PluginDescriptor>)PluginManager.AllPlugins) .Exists(a => a.PluginFileName == plugTemp.PluginFileName)) { strErrorMsg = "the Module has existed!"; bolCheck = false; } else { } } var pluginsVersions = plugTemp.Version.Split('.'); if (pluginsVersions.Length < 4) { strErrorMsg = "the Module's Version format is error! Correct Format is '40.1.20160911.01'"; bolCheck = false; } } else { System.IO.Directory.Delete(strPathTemp, true); strErrorMsg = "Zip File is not a Module!"; } if (bolCheck) { string strPathTo = string.Format("{0}Plugins\\{1}", Request.PhysicalApplicationPath, plugTemp.SystemName); var plug = plugTemp; if (!Directory.Exists(strPathTo)) { Directory.CreateDirectory(strPathTo); System.IO.File.Copy(strPathTemp + "\\Description.txt", strPathTo + "\\Description.txt"); } plug.InstallFrom = pad; plug.NeedInstalled = false; plug.Installed = false; plug.PluginPath = strPathTo; PluginFileParser.SavePluginDescriptionFile(plug); PluginManager.SavePlugins(plug); } } strName = System.IO.Path.GetFileName(strPath); } catch (Exception ex) { strErrorMsg = "Server Error:" + ex.Message; } if (strErrorMsg != "") { return(Json(new UploadMessageError("1", strErrorMsg, Request["id"]), JsonRequestBehavior.AllowGet)); } else { return(Json(new UploadMessageSuccess(new UploadMessageSuccessMsg(strName, "/temp/" + strName), Request["id"]), JsonRequestBehavior.AllowGet)); } }