コード例 #1
0
ファイル: AWFilesForm.cs プロジェクト: VISTALL/game-updater
        private void _startBtn_Click(object sender, EventArgs e)
        {
            ThreadStart a = delegate
                                {
                                    putToList();

                                    if (!Directory.Exists(SelectedPath))
                                    {
                                        Directory.CreateDirectory(SelectedPath);
                                    }
                                    string listFile = DescriptionPath + "/list.zip";
                                    if (File.Exists(listFile))
                                    {
                                        File.Delete(listFile);
                                    }
                                    var list = new FileInfo(listFile);
                                    var listStream = new ZipOutputStream(list.Create());

                                    var listEntry = new ZipEntry("list.lst") {DateTime = DateTime.Now};
                                    listStream.PutNextEntry(listEntry);

                                    onStart();

                                    writeString(listStream, "#Version: " + Version + "\n");

                                    for (var i = 0; i < _files.Count; i++) //листаем
                                    {
                                        var item = _files[i];

                                        item.validateDirectoryes();

                                        FileStream sourceStream = item.CreateSource();
                                        FileStream descriptionStream = item.CreateDescription();

                                        var zipDescriptionStream = new ZipOutputStream(descriptionStream);
                                        //открываем стрим
                                        zipDescriptionStream.SetLevel(9);
                                        // zipDescriptionStream.Password = PASSWORD;

                                        var entry = new ZipEntry(item.EntryName.Replace(".zip", ""))
                                                        {DateTime = item.SourceTime()};
                                        zipDescriptionStream.PutNextEntry(entry);

                                        var bytes = new byte[sourceStream.Length];
                                        int readLen = sourceStream.Read(bytes, 0, bytes.Length);
                                        sourceStream.Close();

                                        if (readLen != bytes.Length)
                                        {
                                            continue;
                                        }

                                        zipDescriptionStream.Write(bytes, 0, readLen);

                                        zipDescriptionStream.Finish();
                                        zipDescriptionStream.Close();

                                        writeString(listStream, item.FileName + "\t" + item.MD5 + "\n");

                                        var p = ((100*i)/_files.Count);
                                        if (p > 100)
                                            p = 100;

                                        setValue(p);
                                    }

                                    listStream.Finish();
                                    listStream.Close();

                                    onEnd();
                                };

            new Thread(a).Start();
        }
コード例 #2
0
ファイル: Maker.cs プロジェクト: VISTALL/game-updater
        public void make()
        {
            if (_files.Count == 0)
            {
                _log.Info("Files == 0");
                MessageBox.Show("Files is none", "Premaker", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

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

            FileInfo listZIP = new FileInfo(DescriptionDirectory + "/list.zip");
            ZipOutputStream zipListStream = new ZipOutputStream(listZIP.Create());
            zipListStream.SetLevel(COMPRESS_LEVEL); //уровень компресии
            zipListStream.Password = PASSWORD; //пароль

            ZipEntry listEntry = new ZipEntry("list.lst");
            listEntry.DateTime = DateTime.Now;
            zipListStream.PutNextEntry(listEntry);

            writeString(zipListStream, "#Revision:" + REVISION + "\n"); //пишем номер ревизии

            ChooseForm.Instance.FormAsGameFiles.onStart(); //прогресс бар включаем
            ChooseForm.Instance.FormAsGameFiles.disableItems(false); //отключаем что б не изменилось

            for (int i = 0; i < Items.Count; i++) //листаем
            {
                if (Break)
                {
                    ChooseForm.Instance.FormAsGameFiles.setStatus("Break");
                    ChooseForm.Instance.FormAsGameFiles.setValue(0);
                    return;
                }

                lock (zipListStream)
                {

                    ListFile item = Items[i];

                    try
                    {
                        if (!item.Exists())
                        {
                            _log.Info("WTF source file is deleted ??. File: " + item.SourceDirectoryName + item.FileName);
                            continue;
                        }

                        if (item.FileType != ListFileType.DELETE)
                        {
                            item.validateDirectoryes();

                            FileStream sourceStream = item.CreateSource();
                            FileStream descriptionStream = item.CreateDescription();

                            if (sourceStream == null || descriptionStream == null)
                            {
                                _log.Info("WTF streams NULL???. File: " + item.FileName);
                            }

                            ChooseForm.Instance.FormAsGameFiles.setStatus("Compressing " + item.FileName);

                            ZipOutputStream zipDescriptionStream = new ZipOutputStream(descriptionStream);
                                //открываем стрим
                            zipDescriptionStream.SetLevel(COMPRESS_LEVEL);
                            zipDescriptionStream.Password = PASSWORD;

                            ZipEntry entry = new ZipEntry(item.EntryName.Replace(".zip", ""));
                            entry.DateTime = item.SourceTime();
                            zipDescriptionStream.PutNextEntry(entry);

                            byte[] bytes = new byte[sourceStream.Length];
                            int readLen = sourceStream.Read(bytes, 0, bytes.Length);
                            sourceStream.Close();

                            if (readLen != bytes.Length)
                            {
                                _log.Info("WTF source file is not compled read??. File: " + item.FileName);
                                continue;
                            }

                            zipDescriptionStream.Write(bytes, 0, readLen);

                            zipDescriptionStream.Finish();
                            zipDescriptionStream.Close();
                        }

                        writeString(zipListStream, item.FileName + "\t" + item.FileType + "\t" + item.MD5 + "\n");
                    }
                    catch (Exception e)
                    {
                        _log.Info("Exception: file - " + item.FileName, e);
                    }
                    finally
                    {
                        int p = ((100 * i) / Items.Count);
                        if (p > 100)
                            p = 100;
                        ChooseForm.Instance.FormAsGameFiles.setValue(p);
                    }
                }
            }

            zipListStream.Finish();
            zipListStream.Close();

            ChooseForm.Instance.FormAsGameFiles.setStatus("Done");
            ChooseForm.Instance.FormAsGameFiles.disableItems(true);
            ChooseForm.Instance.FormAsGameFiles.onEnd();
        }