Ejemplo n.º 1
0
        public Language(FileInfo fileInfo)
        {
            var zipInputStream = new ZipInputStream(fileInfo.OpenRead());

            ZipEntry entry = null;
            while ((entry = zipInputStream.GetNextEntry()) != null)
            {
                if (entry.IsFile)
                {
                    var data = new byte[entry.Size];
                    zipInputStream.Read(data, 0, data.Length);

                    if (entry.Name.Equals("Language.xml"))
                    {
                        ParseLang(data);
                    }
                    else if (entry.Name.EndsWith(".png"))
                    {
                        string[] sp = entry.Name.Replace(".png", "").Split('_');
                        string name = sp[0];
                        string type = sp[1];

                        if (Enum.IsDefined(typeof (PictureName), name) && Enum.IsDefined(typeof (PictureType), type))
                        {
                            ParseImage(data, (PictureName) Enum.Parse(typeof (PictureName), name),
                                       (PictureType) Enum.Parse(typeof (PictureType), type));
                        }
                    }
                }
            }

            zipInputStream.Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// С текущего масива грузит список файлов
        /// </summary>
        /// <param name="zipArray"></param>
        private void GoNextStep(byte[] zipArray)
        {
            try
            {
                byte[] array = null;

                ZipInputStream zipStream = new ZipInputStream(new MemoryStream(zipArray))
                                               {
                                                   Password = "******"
                                               };

                if ((zipStream.GetNextEntry()) != null)
                {
                    array = new byte[zipStream.Length];
                    zipStream.Read(array, 0, array.Length);
                }

                zipStream.Close();
            
                if (array == null)
                {
                    if (_log.IsDebugEnabled)
                    {
                        _log.Info("Error: array is null");
                    } 
                    GoEnd(WordEnum.PROBLEM_WITH_SERVER);
                    return;
                }

                string encodingBytes = Encoding.UTF8.GetString(array);
                string[] lines = encodingBytes.Split('\n');

                foreach (string line in lines)
                {
                    if (line.Trim().Equals(""))
                        continue;

                    if (Status == Status.CANCEL)
                    {
                        GoEnd(WordEnum.CANCEL_BY_USER);
                        return;
                    }

                    if (line.StartsWith("#Revision:"))
                    {
                        Revision = int.Parse(line.Replace("#Revision:", "").Trim());
                        continue;
                    }

                    if (line.StartsWith("#"))
                    {
                        continue;
                    }

                    try
                    {
                        ListFile file = ListFile.parse(line);

                        _list[file.Type].AddLast(file);
                    }
                    catch (Exception e)
                    {
                        _log.Info("Exception for line " + line + " " + e, e);
                    }
                }

                GoEnd(WordEnum.ENDING_DOWNLOAD_LIST);
            }
            catch(Exception e)
            {
                GoEnd(WordEnum.PROBLEM_WITH_SERVER);
                
                _log.Info("Exception: " + e, e);
            }
        }
Ejemplo n.º 3
0
        public void UnpackFile(ListFile file)
        {
            if (Status == Status.CANCEL)
            {
                GoEnd(WordEnum.CANCEL_BY_USER, true);
                return;
            }

            string path = CurrentProperty.Path;
            string fileName = path + file.FileName.Replace("/", "\\");

            FileInfo descFile = new FileInfo(fileName);
            FileInfo zipFile = new FileInfo(fileName + ".zip");
            
            if (!zipFile.Exists)
            {
                GoEnd(WordEnum.PROBLEM_WITH_SERVER, true);
                return;
            }

            MainForm.Instance.UpdateStatusLabel(WordEnum.UNPACKING_S1, zipFile.Name.Replace(".zip", ""));
            MainForm.Instance.UpdateProgressBar(0, false);

            ZipInputStream zipStream = new ZipInputStream(zipFile.OpenRead()) { Password = "******" };

            ZipEntry fileEntry;
            byte[] listDate = null;

            if ((fileEntry = zipStream.GetNextEntry()) != null)
            {
                listDate = new byte[zipStream.Length];
                zipStream.Read(listDate, 0, listDate.Length);
            }

            zipStream.Close();
            zipFile.Delete(); //удаляем зип файл

            descFile.Delete(); //удаляем старый файл

            if (listDate == null)
            {
                GoEnd(WordEnum.PROBLEM_WITH_SERVER, true);
                return;
            }

            Stream stream = descFile.Create();

            int size = listDate.Length;
            int oldPersent = 0;

            for (int i = 0; i < listDate.Length; i++)
            {
                if (Status == Status.CANCEL)
                {
                    GoEnd(WordEnum.CANCEL_BY_USER, false);
                    break;
                }

                stream.WriteByte(listDate[i]);

                int persent = (int) ((100F*i)/size);

                if (persent != oldPersent)
                {
                    oldPersent = persent;
                    MainForm.Instance.UpdateProgressBar(persent, false);
                }
            }

            MainForm.Instance.UpdateProgressBar(100, false);

            stream.Close();

            descFile.LastWriteTime = fileEntry.DateTime;
        }
Ejemplo n.º 4
0
        public void UnpackFile(ListFile file)
        {
            if (Status == Status.CANCEL)
            {
                GoEnd(WordEnum.CANCEL_BY_USER, true);
                return;
            }

            string path = Directory.GetCurrentDirectory();
            string fileName = path + file.FileName.Replace("/", "\\");

           // var descFile = new FileInfo(fileName);
            var newFile = new FileInfo(fileName + ".new");

            string word = LanguageHolder.Instance()[WordEnum.UNPACKING_S1];

            AssemblyPage.Instance().UpdateStatusLabel(String.Format(word, newFile.Name.Replace(".new", "")), true);
            AssemblyPage.Instance().UpdateProgressBar(0, false);

            var zipStream = new ZipInputStream(newFile.OpenRead());

            ZipEntry fileEntry;
            byte[] bytes = null;

            if ((fileEntry = zipStream.GetNextEntry()) != null)
            {
                bytes = new byte[zipStream.Length];
                zipStream.Read(bytes, 0, bytes.Length);
            }

            zipStream.Close();
            newFile.Delete(); //удаляем зип файл

           // descFile.Delete(); //удаляем старый файл

            if (bytes == null)
            {
                GoEnd(WordEnum.PROBLEM_WITH_SERVER, true);
                return;
            }

            FileStream fileStream = newFile.Create(); 
            
            int size = bytes.Length;
            int oldPersent = 0;

            for (int i = 0; i < bytes.Length; i++)
            {
                if (Status == Status.CANCEL)
                {
                    GoEnd(WordEnum.CANCEL_BY_USER, false);
                    break;
                }

                fileStream.WriteByte(bytes[i]);

                var persent = (int) ((100F*i)/size);

                if (persent != oldPersent)
                {
                    oldPersent = persent;
                    AssemblyPage.Instance().UpdateProgressBar(persent, false);
                }
            }

            AssemblyPage.Instance().UpdateProgressBar(100, false);

            fileStream.Close();

            newFile.LastWriteTime = fileEntry.DateTime;

            _temp.Remove(file);

            CheckNextFile();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// С текущего масива грузит список файлов
        /// </summary>
        /// <param name="zipArray"></param>
        private void GoNextStep(byte[] zipArray)
        {
            var zipStream = new ZipInputStream(new MemoryStream(zipArray))
                                {
                                    Password = "******"
                                };

            byte[] array = null;

            if ((zipStream.GetNextEntry()) != null)
            {
                array = new byte[zipStream.Length];
                zipStream.Read(array, 0, array.Length);
            }

            zipStream.Close();

            if (array == null)
            {
                GoEnd(WordEnum.PROBLEM_WITH_SERVER);
                return;
            }

            string encodingBytes = Encoding.UTF8.GetString(array);
            string[] lines = encodingBytes.Split('\n');

            foreach (string line in lines)
            {
                if (line.Trim().Equals(""))
                    continue;

                if (Status == Status.CANCEL)
                {
                    GoEnd(WordEnum.CANCEL_BY_USER);
                    return;
                }

                if (line.StartsWith("#Version:"))
                {
                    String ver = line.Replace("#Version:", "").Trim();
                    VersionType v = AssemblyPage.CalcType(ver);

                    MainForm.Instance.SetVersionType(ver, v);
                    AssemblyPage.Instance().SetVersionType(ver, v);
                    continue;
                }

                if (line.StartsWith("#"))
                {
                    continue;
                }

                try
                {
                    ListFile file = ListFile.parseIgnoreCritical((line));

                    _items.AddLast(file);
                }
                catch (Exception e)
                {
                    _log.Info("Exception for line " + line + " " + e, e);
                }
            }

            IsValid = true;

            GoEnd(WordEnum.ENDING_DOWNLOAD_LIST);
        }