コード例 #1
0
ファイル: UZip.cs プロジェクト: rafeyhusain/InfinityChess
        public static void Unzip(string zipPathAndFile, string outputFolder, string password, bool deleteZipFile)
        {
            ZipInputStream s = new ZipInputStream(File.OpenRead(zipPathAndFile));

            if (password != null && password != String.Empty)
            {
                s.Password = password;
            }
            ZipEntry theEntry;
            string   tmpEntry = String.Empty;

            while ((theEntry = s.GetNextEntry()) != null)
            {
                string directoryName = outputFolder;
                string fileName      = Path.GetFileName(theEntry.Name);
                // create directory
                if (directoryName != "")
                {
                    Directory.CreateDirectory(directoryName);
                }
                if (fileName != String.Empty)
                {
                    if (theEntry.Name.IndexOf(".ini") < 0)
                    {
                        string fullPath = directoryName + "\\" + theEntry.Name;
                        fullPath = fullPath.Replace("\\ ", "\\");
                        string fullDirPath = Path.GetDirectoryName(fullPath);
                        if (!Directory.Exists(fullDirPath))
                        {
                            Directory.CreateDirectory(fullDirPath);
                        }

                        UFile.Delete(fullPath);

                        FileStream streamWriter = File.Create(fullPath);

                        int    size = 2048;
                        byte[] data = new byte[2048];
                        while (true)
                        {
                            size = s.Read(data, 0, data.Length);
                            if (size > 0)
                            {
                                streamWriter.Write(data, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        }
                        streamWriter.Close();
                    }
                }
            }
            s.Close();
            if (deleteZipFile)
            {
                File.Delete(zipPathAndFile);
            }
        }
コード例 #2
0
        private void Delete()
        {
            if (BeforeDelete != null)
            {
                BeforeDelete(this, EventArgs.Empty);
            }

            UFile.Delete(UWeb.MapPath(Url));

            SetValue(Url, ToolTip);

            if (AfterDelete != null)
            {
                AfterDelete(this, EventArgs.Empty);
            }
        }
コード例 #3
0
        private void Save()
        {
            if (BeforeSave != null)
            {
                BeforeSave(this, EventArgs.Empty);
            }

            bs.Visible = bc.Visible = false;
            be.Visible = bd.Visible = true;
            fu.Visible = false;

            if (PostedFileName != "")
            {
                string path = UWeb.MapPath(Url);

                if (path == "")
                {
                    path = UrlFolder;
                }
                {
                    UFile.Delete(path);
                }

                if (!RetainFileNameInEdit)
                {
                    path = UFile.GetFolder(path) + PostedFileName;
                }

                SaveAs(path);
            }

            SetValue(Url, ToolTip);

            if (AfterSave != null)
            {
                AfterSave(this, EventArgs.Empty);
            }
        }
コード例 #4
0
        private void SaveUserImage(string filePath)
        {
            DataTable  userImageTable = new DataTable("UserImageTable");
            DataColumn nameColumn;

            nameColumn            = new DataColumn();
            nameColumn.DataType   = System.Type.GetType("System.String");
            nameColumn.ColumnName = "ImageName";
            userImageTable.Columns.Add(nameColumn);
            DataColumn imageColumn;

            imageColumn            = new DataColumn();
            imageColumn.DataType   = System.Type.GetType("System.Byte[]");
            imageColumn.ColumnName = "ImageBytes";
            userImageTable.Columns.Add(imageColumn);

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            MemoryStream ms = new MemoryStream(encoding.GetBytes(UserImage));

            userImageTable.ReadXml(ms);
            ms.Close();

            //Image img = Image.FromStream(ms);
            if (userImageTable != null && userImageTable.Rows.Count > 0)
            {
                MemoryStream memoryStream = new MemoryStream((byte[])userImageTable.Rows[0]["ImageBytes"]);
                Bitmap       img          = new Bitmap(memoryStream);

                UFile.Delete(filePath + ".bmp");
                UFile.Delete(filePath + ".jpeg");
                UFile.Delete(filePath + ".jpg");
                UFile.Delete(filePath + ".gif");
                UFile.RemoveReadOnly(filePath + UserImageType);

                img.Save(filePath + UserImageType);
                memoryStream.Close();
            }
        }