Beispiel #1
0
        private void WebClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            State = UpdaterState.Idle;

            File.WriteAllText(changelogFilePath, changelog);
            File.WriteAllText(versionFilePath, latestRelease.TagName.Replace("v", ""));

            List <string> updateFiles = Directory.GetFiles(updatePath).ToList();

            updateFiles.ForEach(x => File.Delete(x));

            if (ZipFile.IsZipFile(downloadFilePath) && ZipFile.CheckZip(downloadFilePath))
            {
                using (ZipFile zip = new ZipFile(downloadFilePath))
                    zip.ExtractAll(updatePath, ExtractExistingFileAction.OverwriteSilently);

                if (File.Exists(downloadFilePath))
                {
                    File.Delete(downloadFilePath);
                }
            }
            else
            {
                string newFilePath = $@"{updatePath}\{Path.GetFileName(downloadFilePath)}";
                File.Move(downloadFilePath, newFilePath);
            }

            DownloadingCompleted?.Invoke(this, new VersionEventArgs(currentVersion, latestVersion, false, changelog));
        }
        internal async Task Restore(string filename, Action <SaveProgressEventArgs> backupHandler, Action <RestoreProgressEventArgs> progressHandler)
        {
            //before anything else: if checksum given, compare them
            if (Regex.IsMatch(filename, @"\[([0-9A-F]{8})\]\.zip", RegexOptions.Compiled | RegexOptions.IgnoreCase))
            {
                Match  m         = Regex.Match(filename, @"\[([0-9A-F]{8})\]\.zip", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                string givenHash = m.Result("$1");
                string hash      = string.Empty;
                using (Crc32 crc32 = new Crc32()) { using (FileStream fs = File.Open(filename, FileMode.Open)) { hash = crc32.ComputeHash(fs).Aggregate(hash, (current, b) => current + b.ToString("x2").ToLower()); } }
                if (!string.Equals(givenHash, hash, StringComparison.CurrentCultureIgnoreCase))
                {
                    MessageBox.Show("Checksum missmatch. We can't restore this file.");
                    return;
                }
                if (!ZipFile.CheckZip(filename))
                {
                    MessageBox.Show("The given file is not a valid zip file. We can't restore this file.");
                    return;
                }
            }
            if (MessageBox.Show("Restoring a backup will remove all currently installed mods. A backup will be created automatically.\r\nDo you want to continue?", "Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                await Backup(backupHandler);

                progressHandler(new RestoreProgressEventArgs("Initializing restore", 0, 100, false));

                await Task.Factory.StartNew(() =>
                {
                    progressHandler(new RestoreProgressEventArgs("Cleaning mod folder", 0, 100, false));
                    //Directory.Delete(Settings.Default.ModPath, true);
                    //we don't want to delete the mods folder, so loop over each subfolder
                    Program.CleanFolderContents(Settings.Default.ModPath);
                    progressHandler(new RestoreProgressEventArgs("Restoring folder", 0, 100, false));


                    using (ZipFile zip = ZipFile.Read(filename))
                    {
                        progressHandler(new RestoreProgressEventArgs("Restoring", 0, zip.Count, false));
                        zip.ExtractProgress += (object sender, ExtractProgressEventArgs e) =>
                        {
                            if (e.EventType == ZipProgressEventType.Extracting_AfterExtractEntry)
                            {
                                if (e.EntriesExtracted % 10 == 0 || e.EntriesExtracted == e.EntriesTotal)
                                {
                                    progressHandler(new RestoreProgressEventArgs("Restoring: " + e.CurrentEntry.FileName.Split('/').First(), e.EntriesExtracted, e.EntriesTotal, false));
                                }
                            }
                            else if (e.EventType == ZipProgressEventType.Extracting_AfterExtractAll)
                            {
                                progressHandler(new RestoreProgressEventArgs("Finished", e.EntriesExtracted, e.EntriesTotal, true));
                            }
                        };
                        zip.ExtractAll(Settings.Default.ModPath, ExtractExistingFileAction.OverwriteSilently);
                    }
                });

                MessageBox.Show("Restore completed");
            }
        }
Beispiel #3
0
        public void Installo8c(string filename)
        {
            try
            {
                Log.InfoFormat("Checking if zip file {0}", filename);
                if (!Ionic.Zip.ZipFile.IsZipFile(filename))
                {
                    throw new UserMessageException("This is not a valid o8c file.");
                }
                Log.InfoFormat("Checking if zip file {0}", filename);
                if (!ZipFile.CheckZip(filename))
                {
                    throw new UserMessageException("This is not a valid o8c file.");
                }

                Guid gameGuid = Guid.Empty;

                Log.InfoFormat("Reading zip file {0}", filename);
                using (var zip = ZipFile.Read(filename))
                {
                    Log.InfoFormat("Getting zip files {0}", filename);
                    var selection = from e in zip.Entries where !e.IsDirectory select e;

                    foreach (var e in selection)
                    {
                        Log.InfoFormat("Checking zip file {0} {1}", e.FileName, filename);
                        if (e.FileName.ToLowerInvariant().EndsWith("db"))
                        {
                            continue;
                        }
                        bool extracted = extract(e, out gameGuid, gameGuid);
                        if (!extracted)
                        {
                            Log.Warn(string.Format("Invalid entry in {0}. Entry: {1}.", filename, e.FileName));
                            throw new UserMessageException(
                                      "Image pack invalid. Please contact the game developer about this.");
                        }
                        Log.InfoFormat("Extracted {0} {1}", e.FileName, filename);
                    }
                }
                Log.InfoFormat("Installed successfully {0}", filename);

                //zipFile.ExtractAll(Paths.Get().DatabasePath,ExtractExistingFileAction.OverwriteSilently);
            }
            catch (ZipException e)
            {
                throw new UserMessageException("The o8c file {0} is invalid.", filename);
            }
            catch (UserMessageException e)
            {
                Log.Warn("User message error", e);
                throw;
            }
            catch (Exception e)
            {
                Log.Error("", e);
                throw new UserMessageException("There was an error. If this keeps happening please let us know.");
            }
        }
        public void ValidateZip()
        {
            if (!Present)
            {
                throw new FileNotFoundException("No ServiceControl Monitoring zip file found", FilePath);
            }

            if (!ZipFile.CheckZip(FilePath))
            {
                throw new Exception($"Corrupt Zip File - {FilePath}");
            }
        }
Beispiel #5
0
        public void Installo8c(string filename)
        {
            try
            {
                Log.InfoFormat("Checking if zip file {0}", filename);
                if (!Ionic.Zip.ZipFile.IsZipFile(filename))
                {
                    throw new UserMessageException(L.D.Exception__CanNotInstallo8cInvalid_Format, filename);
                }
                Log.InfoFormat("Checking if zip file {0}", filename);
                if (!ZipFile.CheckZip(filename))
                {
                    throw new UserMessageException(L.D.Exception__CanNotInstallo8cInvalid_Format, filename);
                }

                Guid gameGuid = Guid.Empty;

                Log.InfoFormat("Reading zip file {0}", filename);
                using (var zip = ZipFile.Read(filename))
                {
                    Log.InfoFormat("Getting zip files {0}", filename);
                    var selection = from e in zip.Entries where !e.IsDirectory select e;

                    foreach (var e in selection)
                    {
                        Log.DebugFormat("Checking zip file {0} {1}", e.FileName, filename);
                        if (e.FileName.ToLowerInvariant().EndsWith("db"))
                        {
                            continue;
                        }
                        bool extracted = extract(e, out gameGuid, gameGuid);
                        if (!extracted)
                        {
                            Log.Warn(string.Format("Invalid entry in {0}. Entry: {1}.", filename, e.FileName));
                            throw new UserMessageException(L.D.Exception__CanNotInstallo8cInvalid_Format, filename);
                        }
                        Log.DebugFormat("Extracted {0} {1}", e.FileName, filename);
                    }
                }
                Log.InfoFormat("Installed successfully {0}", filename);

                //zipFile.ExtractAll(Config.Instance.Paths.DatabasePath,ExtractExistingFileAction.OverwriteSilently);
            }
            catch (ZipException e)
            {
                throw new UserMessageException(String.Format(L.D.Exception__CanNotInstallo8cInvalid_Format, filename), e);
            }
            catch (UserMessageException e)
            {
                Log.Warn("User message error", e);
                throw;
            }
        }
        public static void ValidateZip(this PlatformZipInfo zipInfo)
        {
            if (!zipInfo.Present)
            {
                throw new FileNotFoundException($"No {zipInfo.Name} zip file found", zipInfo.FilePath);
            }

            if (!ZipFile.CheckZip(zipInfo.FilePath))
            {
                throw new Exception($"Corrupt Zip File - {zipInfo.FilePath}");
            }
        }
Beispiel #7
0
 public Status ValidateInput(InstallerContext context)
 {
     try
     {
         if (ZipFile.CheckZip((string)context.SourceLocation))
         {
             return(new Status.Success(null));
         }
         return(new Status.Failure(new ZipException("Inconsistent Zip Dictionary")));
     }
     catch (Exception e)
     {
         return(new Status.Failure(e));
     }
 }
        // These two data types are supported in DotNetZip, but only if .NET Framework is targeted.
        //private SelfExtractorFlavor _selfExtractorFlavor;
        //private SelfExtractorSaveOptions _selfExtractorSaveOptions;

        public void CallAll()
        {
            // These two apis are supported in DotNetZip, but only if .NET Framework is targeted.
            //_zipFile.SaveSelfExtractor(_string, _selfExtractorFlavor);
            //_zipFile.SaveSelfExtractor(_string, _selfExtractorSaveOptions);

            //Project: Ionic.Zip
            _bZip2InputStream.Close();
            _bZip2InputStream.Flush();
            _int  = _bZip2InputStream.Read(_bytes, _int, _int);
            _int  = _bZip2InputStream.ReadByte();
            _long = _bZip2InputStream.Seek(_long, _seekOrigin);
            _bZip2InputStream.SetLength(_long);
            _bZip2InputStream.Write(_bytes, _int, _int);
            _bZip2OutputStream.Close();
            _bZip2OutputStream.Flush();
            _int  = _bZip2OutputStream.Read(_bytes, _int, _int);
            _long = _bZip2OutputStream.Seek(_long, _seekOrigin);
            _bZip2OutputStream.SetLength(_long);
            _bZip2OutputStream.Write(_bytes, _int, _int);
            _parallelBZip2OutputStream.Close();
            _parallelBZip2OutputStream.Flush();
            _int  = _parallelBZip2OutputStream.Read(_bytes, _int, _int);
            _long = _parallelBZip2OutputStream.Seek(_long, _seekOrigin);
            _parallelBZip2OutputStream.SetLength(_long);
            _parallelBZip2OutputStream.Write(_bytes, _int, _int);
            _crc32.Combine(_int, _int);
            _int = _crc32.ComputeCrc32(_int, _byte);
            _int = _crc32.GetCrc32(_stream);
            _int = _crc32.GetCrc32AndCopy(_stream, _stream);
            _crc32.Reset();
            _crc32.SlurpBlock(_bytes, _int, _int);
            _crc32.UpdateCRC(_byte);
            _crc32.UpdateCRC(_byte, _int);
            _crcCalculatorStream.Close();
            _crcCalculatorStream.Flush();
            _int  = _crcCalculatorStream.Read(_bytes, _int, _int);
            _long = _crcCalculatorStream.Seek(_long, _seekOrigin);
            _crcCalculatorStream.SetLength(_long);
            _crcCalculatorStream.Write(_bytes, _int, _int);
            _zipEntriesCollection = _fileSelector.SelectEntries(_zipFile);
            _zipEntriesCollection = _fileSelector.SelectEntries(_zipFile, _string);
            _stringsCollection    = _fileSelector.SelectFiles(_string);
            _stringsReadOnly      = _fileSelector.SelectFiles(_string, _bool);
            _string = _fileSelector.ToString();
            _bool   = _comHelper.CheckZip(_string);
            _bool   = _comHelper.CheckZipPassword(_string, _string);
            _comHelper.FixZipDirectory(_string);
            _string = _comHelper.GetZipLibraryVersion();
            _bool   = _comHelper.IsZipFile(_string);
            _bool   = _comHelper.IsZipFileWithExtract(_string);
            _countingStream.Adjust(_long);
            _countingStream.Flush();
            _int  = _countingStream.Read(_bytes, _int, _int);
            _long = _countingStream.Seek(_long, _seekOrigin);
            _countingStream.SetLength(_long);
            _countingStream.Write(_bytes, _int, _int);
            _zipEntry.Extract();
            _zipEntry.Extract(_extractExistingFileAction);
            _zipEntry.Extract(_string);
            _zipEntry.Extract(_string, _extractExistingFileAction);
            _zipEntry.Extract(_stream);
            _zipEntry.ExtractWithPassword(_extractExistingFileAction, _string);
            _zipEntry.ExtractWithPassword(_string);
            _zipEntry.ExtractWithPassword(_string, _extractExistingFileAction, _string);
            _zipEntry.ExtractWithPassword(_string, _string);
            _zipEntry.ExtractWithPassword(_stream, _string);
            _crcCalculatorStream = _zipEntry.OpenReader();
            _crcCalculatorStream = _zipEntry.OpenReader(_string);
            _zipEntry.SetEntryTimes(_datetime, _datetime, _datetime);
            _string   = _zipEntry.ToString();
            _zipEntry = _zipFile.AddDirectory(_string);
            _zipEntry = _zipFile.AddDirectory(_string, _string);
            _zipEntry = _zipFile.AddDirectoryByName(_string);
            _zipEntry = _zipFile.AddEntry(_string, _bytes);
            _zipEntry = _zipFile.AddEntry(_string, _openDelegate, _closeDelegate);
            _zipEntry = _zipFile.AddEntry(_string, _writeDelegate);
            _zipEntry = _zipFile.AddEntry(_string, _string);
            _zipEntry = _zipFile.AddEntry(_string, _string, _encoding);
            _zipEntry = _zipFile.AddEntry(_string, _stream);
            _zipEntry = _zipFile.AddFile(_string);
            _zipEntry = _zipFile.AddFile(_string, _string);
            _zipFile.AddFiles(_strings);
            _zipFile.AddFiles(_strings, _bool, _string);
            _zipFile.AddFiles(_strings, _string);
            _zipEntry = _zipFile.AddItem(_string);
            _zipEntry = _zipFile.AddItem(_string, _string);
            _zipFile.AddSelectedFiles(_string);
            _zipFile.AddSelectedFiles(_string, _bool);
            _zipFile.AddSelectedFiles(_string, _string);
            _zipFile.AddSelectedFiles(_string, _string, _bool);
            _zipFile.AddSelectedFiles(_string, _string, _string);
            _zipFile.AddSelectedFiles(_string, _string, _string, _bool);
            _bool = _zipFile.ContainsEntry(_string);
            _zipFile.Dispose();
            _zipFile.ExtractAll(_string);
            _zipFile.ExtractAll(_string, _extractExistingFileAction);
            _zipFile.ExtractSelectedEntries(_string);
            _zipFile.ExtractSelectedEntries(_string, _extractExistingFileAction);
            _zipFile.ExtractSelectedEntries(_string, _string);
            _zipFile.ExtractSelectedEntries(_string, _string, _string);
            _zipFile.ExtractSelectedEntries(_string, _string, _string, _extractExistingFileAction);
            _enumerator = _zipFile.GetNewEnum();
            _zipFile.Initialize(_string);
            _zipFile.RemoveEntries(_zipEntriesCollection);
            _zipFile.RemoveEntries(_stringsCollection);
            _zipFile.RemoveEntry(_zipEntry);
            _zipFile.RemoveEntry(_string);
            _int = _zipFile.RemoveSelectedEntries(_string);
            _int = _zipFile.RemoveSelectedEntries(_string, _string);
            _zipFile.Save();
            _zipFile.Save(_string);
            _zipFile.Save(_stream);
            _zipEntriesCollection = _zipFile.SelectEntries(_string);
            _zipEntriesCollection = _zipFile.SelectEntries(_string, _string);
            _string   = _zipFile.ToString();
            _zipEntry = _zipFile.UpdateDirectory(_string);
            _zipEntry = _zipFile.UpdateDirectory(_string, _string);
            _zipEntry = _zipFile.UpdateEntry(_string, _bytes);
            _zipEntry = _zipFile.UpdateEntry(_string, _openDelegate, _closeDelegate);
            _zipEntry = _zipFile.UpdateEntry(_string, _writeDelegate);
            _zipEntry = _zipFile.UpdateEntry(_string, _string);
            _zipEntry = _zipFile.UpdateEntry(_string, _string, _encoding);
            _zipEntry = _zipFile.UpdateEntry(_string, _stream);
            _zipEntry = _zipFile.UpdateFile(_string);
            _zipFile.UpdateFile(_string, _string);
            _zipFile.UpdateFiles(_strings);
            _zipFile.UpdateFiles(_strings, _string);
            _zipFile.UpdateItem(_string);
            _zipFile.UpdateItem(_string, _string);
            _zipFile.UpdateSelectedFiles(_string, _string, _string, _bool);
            _zipInputStream.Flush();
            _zipEntry = _zipInputStream.GetNextEntry();
            _int      = _zipInputStream.Read(_bytes, _int, _int);
            _long     = _zipInputStream.Seek(_long, _seekOrigin);
            _zipInputStream.SetLength(_long);
            _string = _zipInputStream.ToString();
            _zipInputStream.Write(_bytes, _int, _int);
            _bool = _zipOutputStream.ContainsEntry(_string);
            _zipOutputStream.Flush();
            _zipEntry = _zipOutputStream.PutNextEntry(_string);
            _int      = _zipOutputStream.Read(_bytes, _int, _int);
            _long     = _zipOutputStream.Seek(_long, _seekOrigin);
            _zipOutputStream.SetLength(_long);
            _string = _zipOutputStream.ToString();
            _zipOutputStream.Write(_bytes, _int, _int);
            _deflateStream.Flush();
            _int  = _deflateStream.Read(_bytes, _int, _int);
            _long = _deflateStream.Seek(_long, _seekOrigin);
            _deflateStream.SetLength(_long);
            _deflateStream.Write(_bytes, _int, _int);
            _gZipStream.Flush();
            _int  = _gZipStream.Read(_bytes, _int, _int);
            _long = _gZipStream.Seek(_long, _seekOrigin);
            _gZipStream.SetLength(_long);
            _gZipStream.Write(_bytes, _int, _int);
            _parallelDeflateOutputStream.Close();
            _parallelDeflateOutputStream.Flush();
            _int = _parallelDeflateOutputStream.Read(_bytes, _int, _int);
            _parallelDeflateOutputStream.Reset(_stream);
            _long = _parallelDeflateOutputStream.Seek(_long, _seekOrigin);
            _parallelDeflateOutputStream.SetLength(_long);
            _parallelDeflateOutputStream.Write(_bytes, _int, _int);

            // Static
            _bool = ZipFile.CheckZip(_string);
            _bool = ZipFile.CheckZip(_string, _bool, _textWriter);
            _bool = ZipFile.CheckZipPassword(_string, _string);
            ZipFile.FixZipDirectory(_string);
            _bool    = ZipFile.IsZipFile(_string);
            _bool    = ZipFile.IsZipFile(_string, _bool);
            _bool    = ZipFile.IsZipFile(_stream, _bool);
            _zipFile = ZipFile.Read(_string);
            _zipFile = ZipFile.Read(_string, _readOptions);
            _zipFile = ZipFile.Read(_stream);
            _zipFile = ZipFile.Read(_stream, _readOptions);
            _uint    = Adler.Adler32(_uint, _bytes, _int, _int);
            _bytes   = DeflateStream.CompressBuffer(_bytes);
            _bytes   = DeflateStream.CompressString(_string);
            _bytes   = DeflateStream.UncompressBuffer(_bytes);
            _string  = DeflateStream.UncompressString(_bytes);
            _bytes   = GZipStream.CompressBuffer(_bytes);
            _bytes   = GZipStream.CompressString(_string);
            _bytes   = GZipStream.UncompressBuffer(_bytes);
            _string  = GZipStream.UncompressString(_bytes);
            _bytes   = ZlibStream.CompressBuffer(_bytes);
            _bytes   = ZlibStream.CompressString(_string);
            _bytes   = ZlibStream.UncompressBuffer(_bytes);
            _string  = ZlibStream.UncompressString(_bytes);
        }
        /**
         * Project loading routine. It checks for the file format and tries to open it
         * according to the file and TTProject object specifications.
         *
         * (TTP - TT Project - XML)
         * (TTPX - TT Consolidated Project - ZIP)
         *
         * @param  filePath  an absolute URI giving the base location of the project file
         * @return TTProject TranslaTale Project object
         */

        public static TTProject loadProject(string filePath, bool errorMsgs = true)
        {
            byte[]    buffer = new byte[2];
            XDocument xd1    = new XDocument();

            TTProject project = new TTProject("", "", false, false, xd1);

            try
            {
                using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    fs.Read(buffer, 0, buffer.Length);
                    fs.Close();

                    if (System.Text.Encoding.UTF8.GetString(buffer) == "<?") // if XML
                    {
                        try
                        {
                            project.Path             = filePath;
                            project.WorkingPath      = filePath;
                            project.ProjConsolidated = false;
                            project.Err        = false;
                            project.Properties = XDocument.Load(filePath); // XML OK
                            return(project);
                        }
                        catch (XmlException xex)
                        {
                            if (errorMsgs == true)
                            {
                                MessageBox.Show("The chosen file is not a valid TranslaTale project", "Error loading project", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            project.Path             = "";
                            project.WorkingPath      = "";
                            project.ProjConsolidated = false;
                            project.Err        = true;
                            project.Properties = new XDocument();
                            return(project);
                        }
                    }
                    else if (System.Text.Encoding.UTF8.GetString(buffer) == "PK") // if ZIP
                    {
                        try
                        {
                            if (ZipFile.CheckZip(filePath) == true) // ZIP OK
                            {
                                try
                                {
                                    string tmpFolder = ExtractFileToDirectory(filePath);
                                    Process.Start(tmpFolder);
                                    project.Path             = filePath;
                                    project.WorkingPath      = Path.Combine(tmpFolder, @"project.ttp");
                                    project.ProjConsolidated = true;
                                    project.Err        = false;
                                    project.Properties = XDocument.Load(Path.Combine(tmpFolder, @"project.ttp")); // XML OK
                                    return(project);
                                }
                                catch (XmlException xex)
                                {
                                    if (errorMsgs == true)
                                    {
                                        MessageBox.Show("The chosen file is not a valid TranslaTale project", "Error loading project", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    }
                                    project.Path             = "";
                                    project.WorkingPath      = "";
                                    project.ProjConsolidated = true;
                                    project.Err        = true;
                                    project.Properties = new XDocument();
                                    return(project);
                                }
                            }
                            else // Malformed ZIP
                            {
                                if (errorMsgs == true)
                                {
                                    MessageBox.Show("The chosen file is not a valid TranslaTale project", "Error loading project", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                                project.Path             = "";
                                project.WorkingPath      = "";
                                project.ProjConsolidated = true;
                                project.Err        = true;
                                project.Properties = new XDocument();
                                return(project);
                            }
                        }
                        catch (ZipException zex) // Malformed ZIP
                        {
                            if (errorMsgs == true)
                            {
                                MessageBox.Show("The chosen file is not a valid TranslaTale project", "Error loading project", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            project.Path             = "";
                            project.WorkingPath      = "";
                            project.ProjConsolidated = true;
                            project.Err        = true;
                            project.Properties = new XDocument();
                            return(project);
                        }
                    }
                    else
                    {   // Not recognised
                        if (errorMsgs == true)
                        {
                            MessageBox.Show("The chosen file is not a valid TranslaTale project", "Error loading project", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        project.Path             = "";
                        project.WorkingPath      = "";
                        project.ProjConsolidated = false;
                        project.Err        = true;
                        project.Properties = new XDocument();
                        return(project);
                    }
                }
            }
            catch (System.UnauthorizedAccessException fex)
            {   // Not readable
                if (errorMsgs == true)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + fex.Message, "Error loading project", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                project.Path             = "";
                project.WorkingPath      = "";
                project.ProjConsolidated = false;
                project.Err        = true;
                project.Properties = new XDocument();
                return(project);
            }
        }
Beispiel #10
0
 public static bool CheckZip(string path)
 {
     return(ZipFile.CheckZip(path));
 }
Beispiel #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="cloudDir"></param>
        /// <returns>Whether the action was succesful</returns>
        public static bool ZipVerifyAndPutInCloudDir(string filepath, string cloudDir)
        {
            int    dotIndx = filepath.LastIndexOf('.');
            string filepathWithoutExtension = dotIndx == -1
                ?filepath
                :filepath.Substring(0, dotIndx);
            string tempFilename = filepathWithoutExtension + ".zip";
            bool   isFixed;
            ILog   log = null;

            using (ZipFile zip = new ZipFile())
            {
                zip.ParallelDeflateThreshold = -1;

                /*
                 * zip.BufferSize = 1000000;
                 * zip.CodecBufferSize = 1000000;
                 * */

                zip.AddFile(filepath, "");
                zip.Save(tempFilename);

                using (var sw = new StringWriter())
                {
                    if (ZipFile.CheckZip(tempFilename, true, sw))
                    {
                        isFixed = false;
                    }
                    else
                    {
                        sw.Flush();
                        log = GetLog();
                        log.WarnFormat(sw.ToString());
                        isFixed = true;
                    }
                }
            }
            try
            {
                if (isFixed)
                {
                    File.Delete(tempFilename);
                    File.Move(filepathWithoutExtension + "_Fixed.zip", tempFilename);
                }

                using (ZipFile zip = ZipFile.Read(tempFilename))
                {
                    zip[0].Extract(Stream.Null);
                }
                string destName = Path.Combine(cloudDir, Path.GetFileName(tempFilename));
                if (File.Exists(destName))
                {
                    File.Delete(destName);
                }
                File.Move(tempFilename, destName);
                return(true);
            }
            catch (Exception e)
            {
                if (log == null)
                {
                    log = GetLog();
                }
                log.Error("Failed to create zip file - error on test extraction:", e);
                return(false);
            }
        }
Beispiel #12
0
 /// <summary>
 ///  A wrapper for <see cref="ZipFile.CheckZip(string)">ZipFile.CheckZip(string)</see>
 /// </summary>
 /// <param name="filename">The filename to of the zip file to check.</param>
 ///
 /// <returns>true if the named zip file checks OK. Otherwise, false. </returns>
 public bool CheckZip(string filename)
 {
     return(ZipFile.CheckZip(filename));
 }
Beispiel #13
0
 public bool CheckCompressedFile(string filePath)
 {
     return(ZipFile.CheckZip(filePath));
 }
        public bool AddMinecraftJar(string file)
        {
            try
            {
                // Is it a ZIP (JAR) file?
                if (!ZipFile.IsZipFile(file))
                {
                    return(false);
                }

                // Is it a consistent ZIP (JAR) file?
                if (!ZipFile.CheckZip(file))
                {
                    try
                    {
                        ZipFile.FixZipDirectory(file);
                    }
                    catch
                    {
                        return(false);
                    }
                    if (!ZipFile.CheckZip(file))
                    {
                        return(false);
                    }
                }
            }
            catch // zip errors are the most to occur here
            {
                return(false);
            }

            // Does it have minecraft classes?
            ZipFile zf = new ZipFile(file);

            if (!zf.EntryFileNames.Contains("net/minecraft/client/Minecraft.class"))
            {
                return(false);
            }


            List <string> modsList = new List <string>();

            // Minecraft Forge check
            if (zf.EntryFileNames.Contains("mod_MinecraftForge.class") || zf.EntryFileNames.Contains("forge/"))
            {
                modsList.Add("Forge");
            }

            // ModLoader check
            if (zf.EntryFileNames.Contains("ModLoader.class"))
            {
                if (zf.EntryFileNames.Contains("fmlversion.properties"))
                {
                    modsList.Add("Forge ModLoader");
                }
                else
                {
                    modsList.Add("ModLoader");
                }
            }

            // OptiFine check
            if (zf.EntryFileNames.Contains("GuiDetailSettingsOF.class"))
            {
                modsList.Add("OptiFine");
            }

            // TODO: ModLoader check

            // Convert to a static list
            string[] mods = modsList.ToArray();
            modsList = null;

            // Version string
            string VersionString = file + " ";

            VersionString += Environment.NewLine; // TODO: Minecraft version check
            VersionString += mods.Length > 0 ? "(modded with " + string.Join(", ", mods) + ")" : "";

            // Create a control to give the user the option to use that jar!
            RadioButton ctl = new RadioButton();

            ctl.Location = new Point(3, 3);
            ctl.AutoSize = true;
            ctl.Text     = VersionString;
            ctl.Name     = "minecraft_" + jarSwitchPanel.Controls.Count;
            ctl.Checked  = (ctl.TabIndex = jarSwitchPanel.Controls.Count) == 0;
            this.jarSwitchPanel.Controls.Add(ctl);
            this.jarSwitchPanel.SetFlowBreak(ctl, true);
            ctl.Click += new EventHandler(ctl_Click);
            // nice picture for minecraft.jar :D
            List <ZipEntry> zl = zf.SelectEntries("pack.png") as List <ZipEntry>;

            if (zl.Count > 0)
            {
                Image x;

                // Extract image into memory
                using (MemoryStream ms = new MemoryStream())
                {
                    zl[0].Extract(ms);
                    ms.Seek(0, SeekOrigin.Begin);
                    x = Image.FromStream(ms);
                }

                // Resize
                float factor = 32f / x.Height;
                ctl.Image = x.GetThumbnailImage(
                    (int)((float)x.Width * factor),          // width
                    (int)((float)x.Height * factor),         // height
                    new Image.GetThumbnailImageAbort(_GTIA), // unneeded abort callback -_-
                    IntPtr.Zero                              // uhm...
                    );
                ctl.TextImageRelation = TextImageRelation.ImageBeforeText;
            }
            jarList.Add(file);

            return(true);
        }
Beispiel #15
0
 /// <summary>
 /// Checks if the file is a valid zip file
 /// </summary>
 /// <returns></returns>
 public bool CheckZip()
 {
     return(ZipFile.CheckZip(_tempZipPath));
 }