Esempio n. 1
0
        /// <summary>
        /// 升级前备份旧系统文件
        /// </summary>
        /// <param name="rootPath">系统根目录</param>
        /// <param name="backupPath">备份目录</param>
        public static string BackupOldFiles(string rootPath, string backupPath)
        {
            //检查文件夹是否存在
            string tempPath = Path.Combine(rootPath, "_temp\\backupBeforeUpdate");

            if (Directory.Exists(tempPath))
            {
                DirectoryInfo d = new DirectoryInfo(tempPath);
                We7Helper.DeleteFileTree(d);
            }

            //不需要复制的文件夹
            string[] folderList = new string[] { "_data", "_skins",
                                                 "_temp", "_backup", "Plugins", "log" };

            ArrayList     folders = ArrayList.Adapter(folderList);
            DirectoryInfo di      = new DirectoryInfo(rootPath);

            DirectoryInfo[] ds = di.GetDirectories();

            //复制当前网站目录结构,到tempPath
            foreach (DirectoryInfo d in ds)
            {
                if (!folders.Contains(d.Name.ToLower()))
                {
                    We7Helper.CopyDirectory(d.FullName, Path.Combine(tempPath, d.Name));
                }
            }

            FileInfo[] files = di.GetFiles();
            foreach (FileInfo f in files)
            {
                File.Copy(f.FullName, Path.Combine(tempPath, f.Name));
            }

            if (!Directory.Exists(backupPath))
            {
                Directory.CreateDirectory(backupPath);
            }

            string[] FileProperties = new string[2];
            FileProperties[0] = tempPath;                                                                                                           //临时目录,将被压缩
            FileProperties[1] = Path.Combine(backupPath, "backup-" + DateTime.Today.ToString("yyyy-MM-dd-") + DateTime.Now.GetHashCode() + ".zip"); //压缩后的目录

            //压缩文件
            try
            {
                ZipClass.ZipFileMain(FileProperties);

                //压缩之后删除临时文件
                DirectoryInfo d = new DirectoryInfo(tempPath);
                We7Helper.DeleteFileTree(d);

                return(FileProperties[1]);
            }
            catch
            {
            }
            return("");
        }
Esempio n. 2
0
        protected void CreateZip(string FileName)
        {
            //string CopyToPath = Server.MapPath(Constants.TempBasePath);//目标文件夹
            string CopyToPath = String.Format("{0}\\Templates.{1}\\controls", Server.MapPath("~/_temp/"), Path.GetFileNameWithoutExtension(FileName));
            //在目标文件夹 创建文件夹.Files及子文件夹
            string stylesPath = String.Format("{0}\\styles", CopyToPath); //css文件目录
            string groupsPath = String.Format("{0}\\groups", CopyToPath); //模板组文件目录
            string imagePath  = String.Format("{0}\\images", CopyToPath); //模板组文件目录

            Directory.CreateDirectory(stylesPath);
            Directory.CreateDirectory(groupsPath);

            //模板组Jpg预览图片文件
            string JpgFile = Server.MapPath(String.Format("/{0}/{1}.jpg", Constants.TemplateGroupBasePath, FileName));
            //模板组Xml文件
            string XmlFile = Server.MapPath(String.Format("/{0}/{1}", Constants.TemplateGroupBasePath, FileName));



            //拷贝模板组文件
            if (File.Exists(JpgFile))
            {
                File.Copy(JpgFile, String.Format("{0}/{1}.jpg", groupsPath, FileName), true);
            }
            if (File.Exists(XmlFile))
            {
                File.Copy(XmlFile, String.Format("{0}/{1}", groupsPath, FileName), true);
            }

            string imgPath = String.Format("{0}/images", Server.MapPath(Constants.TemplateBasePath));

            CopyFolder(imagePath, imgPath, true);
            string templateFile = Server.MapPath(Constants.TemplateBasePath);

            CopyFolder(CopyToPath, templateFile, false);
            string cssPath = String.Format("{0}/styles", Server.MapPath(Constants.TemplateBasePath));

            CopyFolder(stylesPath, cssPath, true);
            //创建res文件夹
            string resPath = String.Format("{0}\\Templates.{1}\\res", Server.MapPath(Constants.TempBasePath), Path.GetFileNameWithoutExtension(FileName));

            Directory.CreateDirectory(resPath);
            //创建版本文件
            //CreateVersion(resPath);

            string[] FileProperties = new string[2];
            FileProperties[0] = String.Format("{0}\\Templates.{1}", Server.MapPath(Constants.TempBasePath), Path.GetFileNameWithoutExtension(FileName));;   //压缩目录
            //FileProperties[1] = String.Format("{0}/{1}.zip", Server.MapPath(Constants.TemplateGroupBasePath), FileName);//压缩后的目录
            FileProperties[1] = String.Format("{0}/Templates.{1}.zip", Server.MapPath(Constants.TempBasePath), Path.GetFileNameWithoutExtension(FileName)); //压缩后的目录
            //压缩文件
            try
            {
                ZipClass.ZipFileMain(FileProperties);
                DonwloadHyperLink.NavigateUrl = String.Format("~/{0}/Templates.{1}.zip", Constants.TempBasePath.TrimStart('\\').Trim('/'), Path.GetFileNameWithoutExtension(FileName));
                DeleteFolder(String.Format("{0}\\Templates.{1}", Server.MapPath(Constants.TempBasePath), Path.GetFileNameWithoutExtension(FileName)));
            }
            catch
            {
            }
        }
Esempio n. 3
0
        static void ZipConfig()
        {
            string [] FileProperties = new string[2];
            string    Path           = Application.streamingAssetsPath;

            Debug.Log("Path=" + Path);

            //待压缩文件目录
            FileProperties[0] = System.IO.Path.Combine(Path, "Config");
            //压缩后的目标文件
            FileProperties[1] = System.IO.Path.Combine(Path, "Config.zip");
            ZipClass Zc = new ZipClass();

            Zc.ZipFileMain(FileProperties);
        }
Esempio n. 4
0
    void OnGUI()
    {
        if (GUI.Button(new Rect(400, 130, 100, 50), "ZipClass"))
        {
            string [] FileProperties = new string[2];
            //待压缩文件目录
            FileProperties[0] = @"/Users/jiangcheng/Desktop/ziptest";
            //压缩后的目标文件
            FileProperties[1] = @"/Users/jiangcheng/Desktop/a.zip";
            ZipClass Zc = new ZipClass();
            Zc.ZipFileMain(FileProperties);

            //Debug.Log(DeviceInfo.StreamingPath);
//			ZipClass Zc=new ZipClass();
//			Zc.ZipFile(@"/Users/jiangcheng/Desktop/ziptest",@"/Users/jiangcheng/Desktop/a.zip",6,2048);
        }

        if (GUI.Button(new Rect(400, 200, 100, 50), "UnZipClass"))
        {
            string ConfigPath = System.IO.Path.Combine(DeviceInfo.StreamingPath, "Config.zip");
            //string ConfigMD5 = MessageDigest_Algorithm.getFileMd5Hash(ConfigPath);
            Debug.Log(Core.Data.guideManger.getBasePath());

            string [] FileProperties = new string[2];
            //待解压的文件
            FileProperties[0] = ConfigPath;
            //解压后放置的目标目录
            FileProperties[1] = Core.Data.guideManger.getBasePath();
            UnZipClass UnZc = new UnZipClass();
            UnZc.UnZip(FileProperties);
        }

        if (GUI.Button(new Rect(400, 270, 100, 50), "GetMD5"))
        {
            string ConfigPath = System.IO.Path.Combine(DeviceInfo.StreamingPath, "Config.zip");
            string ConfigMD5  = MessageDigest_Algorithm.getFileMd5Hash(ConfigPath);
            Debug.Log(ConfigMD5);
        }

        if (GUI.Button(new Rect(400, 340, 100, 50), "DownLoad"))
        {
            string ConfigPath = System.IO.Path.Combine(DeviceInfo.StreamingPath, "Config.zip");
            string ConfigMD5  = MessageDigest_Algorithm.getFileMd5Hash(ConfigPath);
            test_DownloadResource(ConfigMD5);
        }
    }
Esempio n. 5
0
    public static void BaleZIP()
    {
        string balePath = EditorTools.mExportFolderLocationFloder;

        if (!Directory.Exists(balePath))
        {
            Directory.CreateDirectory(balePath);
        }
        string savePath = EditorTools.mExportFolderLocationFloder + EditorTools.mGame + ".ZIP";

        if (File.Exists(savePath))
        {
            File.Delete(savePath);
        }
        string [] FileProperties = new string[2];
        //待压缩文件目录
        FileProperties[0] = balePath;
        //压缩后的目标文件
        FileProperties[1] = savePath;

        ZipClass Zc = new ZipClass();

        Zc.ZipFileMain(FileProperties);
    }
Esempio n. 6
0
        protected void CreateZip(string FileName)
        {
            //目标文件夹
            string CopyToPath = Server.MapPath("~/_Temp");

            //在目标文件夹 创建文件夹.Files及子文件夹
            Directory.CreateDirectory(CopyToPath + "/" + FileName + ".Files/controls");
            Directory.CreateDirectory(CopyToPath + "/" + FileName + ".Files/res");

            string ascxShotName = "";

            for (int i = 0; i < DataControls.Length; i++)
            {
                ascxShotName = DataControls[i].FileName.Replace(".xml", "");

                // ascx文件
                string AscxFile = Server.MapPath("~/" + Constants.ControlBasePath.Replace("\\", "/")) + "/" + ascxShotName;
                //xml文件
                string AscxXmlFile  = Server.MapPath("~/" + Constants.ControlBasePath.Replace("\\", "/")) + "/" + DataControls[i].FileName;
                string ascxCsFile   = Server.MapPath("~/" + Constants.ControlBasePath.Replace("\\", "/")) + "/" + ascxShotName + ".cs";
                string designerFile = Server.MapPath("~/" + Constants.ControlBasePath.Replace("\\", "/")) + "/" + ascxShotName + ".designer.cs";

                //拷贝到目标文件夹
                if (File.Exists(AscxFile))
                {
                    try
                    {
                        File.Copy(AscxFile, CopyToPath + "/" + FileName + ".Files/controls/" + ascxShotName, true);
                    }
                    catch { }
                }
                if (File.Exists(AscxXmlFile))
                {
                    try   //原xml格式错误
                    {
                        File.Copy(AscxXmlFile, CopyToPath + "/" + FileName + ".Files/controls/" + DataControls[i].FileName, true);
                    }
                    catch { }
                }
                if (File.Exists(ascxCsFile))
                {
                    try
                    {
                        File.Copy(ascxCsFile, CopyToPath + "/" + FileName + ".Files/controls/" + ascxShotName + ".cs", true);
                    }
                    catch { }
                }
                if (File.Exists(designerFile))
                {
                    try
                    {
                        File.Copy(designerFile, CopyToPath + "/" + FileName + ".Files/controls/" + ascxShotName + ".designer.cs", true);
                    }
                    catch { }
                }
            }

            string[] FileProperties = new string[2];
            FileProperties[0] = CopyToPath + "/" + FileName + ".Files";                           //压缩目录
            FileProperties[1] = Server.MapPath(Constants.TempBasePath) + "/" + FileName + ".zip"; //压缩后的目录
            //压缩文件
            try
            {
                ZipClass.ZipFileMain(FileProperties);
                DonwloadHyperLink.NavigateUrl = Constants.TempBasePath + "/" + FileName + ".zip";
            }
            catch
            {
            }
        }
Esempio n. 7
0
        public static bool BackupDatabase(BaseConfigInfo bci, string file)
        {
            string tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "_temp/backupDB");

            if (Directory.Exists(tempPath))
            {
                DirectoryInfo d = new DirectoryInfo(tempPath);
                We7Helper.DeleteFileTree(d);
            }

            DatabaseInfo dbi     = GetDatabaseInfo(bci);
            string       dbFile  = dbi.DBFile.Replace("{$App}", AppDomain.CurrentDomain.BaseDirectory);
            bool         success = false;

            switch (bci.DBType.ToLower())
            {
            case "sqlite":
            case "access":
                File.Copy(dbFile, Path.Combine(tempPath, Path.GetFileName(file)), true);
                success = true;
                break;

            case "sqlserver":
                string masterString = String.Format("Server={0};Database={1};User={2};Password={3}", dbi.Server, "master", dbi.User, dbi.Password);
                string sql          = String.Format("backup database {0} to disk='{1}' with init", dbi.Database, Path.Combine(tempPath, Path.GetFileName(file)));

                //创建数据库
                IDbDriver driver = new SqlDbDriver();
                using (IConnection conn = driver.CreateConnection(masterString))
                {
                    SqlStatement st = new SqlStatement(sql);
                    driver.FormatSQL(st);
                    conn.Update(st);
                }
                success = true;
                break;

            case "mysql":

                break;
            }

            if (success)
            {
                string[] FileProperties = new string[2];
                FileProperties[0] = tempPath; //压缩目录
                FileProperties[1] = file;     //压缩后的目录
                if (File.Exists(FileProperties[1]))
                {
                    File.Delete(FileProperties[1]);
                }

                //压缩文件
                try
                {
                    ZipClass.ZipFileMain(FileProperties);
                }
                catch
                {
                }
            }

            return(success);
        }