Beispiel #1
0
 public static void ExtractRar(string rarFileName, string targetDirectory)
 {
     {
         RarArchive.WriteToDirectory(rarFileName, targetDirectory, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
     }
     // there is some poor coding in RarArchive apparently that causes rarFileName to still be used after extracting - GC.Collect handles that
     GC.Collect();
 }
Beispiel #2
0
        internal static void ExtractFromRarArchive(ExpandTuRarArchiveCommand cmdlet)
        {
            string[] pathToArchive         = cmdlet.ArchiveName;
            string   pathToTargetDirectory = cmdlet.TargetFolder;
//            ExtractExistingFileAction fileAction = ExtractExistingFileAction.DoNotOverwrite;
//            if (cmdlet.Overwrite) {
//                fileAction = ExtractExistingFileAction.OverwriteSilently;
//            }
            var options = ExtractOptions.Overwrite;

            foreach (string path in pathToArchive)
            {
                if (!string.IsNullOrEmpty(path))
                {
                    cmdlet.WriteVerbose(
                        cmdlet,
                        "extracting '" +
                        path +
                        "'");

                    try {
//                        using (Ionic.zipARchive = ZipFile.Read(path)) {
//
//                            cmdlet.WriteVerbose(cmdlet, "opening the archive");
//
//                            foreach (ZipEntry entry in zipARchive) {
//
//                                entry.Extract(pathToTargetDirectory, fileAction);
//                                cmdlet.WriteObject(
//                                    cmdlet,
//                                    pathToTargetDirectory +
//                                    @"\" +
//                                    entry.FileName);
//                            }
//                        }

                        RarArchive.WriteToDirectory(
                            path,
                            pathToTargetDirectory,
                            options);

                        // RarArchive.IsRarFile
                    } catch (Exception eExtract) {
                        cmdlet.WriteError(
                            cmdlet,
                            "Failed to extract archive '" +
                            path +
                            "'. " +
                            eExtract.Message,
                            "FailedToExtract",
                            ErrorCategory.InvalidOperation,
                            false);
                    }
                }
            }
        }
Beispiel #3
0
 // Разархивация базы по комуналке с перемещением
 public static void CopyDB(string pathFrom, string pathTo)
 {
     try
     {
         DirectoryInfo dirTo   = new DirectoryInfo(pathTo);
         DirectoryInfo dirFrom = new DirectoryInfo(pathFrom);
         string        zipArch = ".zip";
         FileInfo[]    files   = dirFrom.GetFiles();
         if (dirTo.Exists)
         {
             for (int i = 0; i < files.Length; i++)
             {
                 string _pathFrom = dirFrom + files[i].Name;
                 if (files[i].Name.Contains(zipArch))
                 {
                     ExtractDistrib(pathFrom, pathTo); // Разархивация .zip
                 }
                 else
                 {
                     RarArchive.WriteToDirectory(_pathFrom, pathTo); // Разархивация .rar
                 }
             }
         }
         else
         {
             dirTo.Create();
             for (int i = 0; i < files.Length; i++)
             {
                 string _pathFrom = dirFrom + files[i].Name;
                 if (files[i].Name.Contains(zipArch))
                 {
                     ExtractDistrib(pathFrom, pathTo); // Разархивация .zip
                 }
                 else
                 {
                     RarArchive.WriteToDirectory(_pathFrom, pathTo); // Разархивация .rar
                 }
             }
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Проверьте правильность путей и наличие rar архива на флешке.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Beispiel #4
0
        private void DownloadAndUnrarUpdate(string link)
        {
            string programmLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string rarName          = "update.rar";

            TryDeleteFile(programmLocation + "\\" + rarName);

            RemoveFiles();

            Status = "Загрузка обновления";
            var client = new WebClient();

            client.DownloadFile(new Uri(link), rarName);

            Status = "Копирование файлов";

            RenameUndeletedFiles(programmLocation);
            RarArchive.WriteToDirectory(rarName, programmLocation,
                                        NUnrar.Common.ExtractOptions.ExtractFullPath | NUnrar.Common.ExtractOptions.Overwrite);
            TryDeleteFile(programmLocation + "\\" + rarName);
        }
        public void UseSampleMap()
        {
            try
            {
                var rarUri     = Path.Combine(MCFireDirectories.Install, "Resources", "SampleWorld.rar");
                var rarDir     = new Uri(rarUri).LocalPath;
                var extractDir = Path.Combine(MCFireDirectories.MCFireAppdata, "SampleWorld");

                try
                {
                    Directory.Delete(extractDir, true);
                }
                catch (DirectoryNotFoundException) { }
                RarArchive.WriteToDirectory(rarDir, MCFireDirectories.MCFireAppdata, ExtractOptions.ExtractFullPath);
                _explorerService.TryAddInstallation(Installation.New(extractDir));
            }
            catch (Exception)
            {
                SampleMapMessage = "Failed extracting sample map";
            }
        }
Beispiel #6
0
        /// <summary>
        /// Позволяет разархивировать zip и rar
        /// </summary>
        /// <param name="pathFrom">От куда брать архив</param>
        /// <param name="pathTo">Куда разархивировать</param>
        public static void ExtractArchive(string pathFrom, string pathTo)
        {
            DirectoryInfo dirFrom = new DirectoryInfo(pathFrom);
            DirectoryInfo dirTo   = new DirectoryInfo(pathTo);

            FileInfo[] files = dirFrom.GetFiles();

            //
            for (int i = 0; i < files.Length; i++)
            {
                string _pathFrom = pathFrom + "\\" + files[i].Name;
                if (files[i].Name.Contains(".zip"))
                {
                    if (dirTo.Exists)
                    {
                        dirTo.Delete(true);
                        // Разархивация .zip
                        ZipFile.ExtractToDirectory(_pathFrom, pathTo);
                    }
                    else
                    {
                        dirTo.Create();
                        // Разархивация .zip
                        ZipFile.ExtractToDirectory(_pathFrom, pathTo);
                    }
                }
                else if (files[i].Name.Contains(".rar"))
                {
                    if (dirTo.Exists)
                    {
                        dirTo.Delete(true);
                    }
                    // Разархивация .rar (ExtractOptions.ExtractFullPath) позволяет разархивировать и папки тоже
                    RarArchive.WriteToDirectory(_pathFrom, pathTo, ExtractOptions.ExtractFullPath);
                }
            }
        }
 public void decompressRAR(string srcPath, string destPath)
 {
     RarArchive.WriteToDirectory(srcPath, destPath);
 }
Beispiel #8
0
        public override void PostInitialize()
#endif
        {
            // remove the toolbox.
            var viewMenu = MainMenu.All.FirstOrDefault(item => item.Name == "View");

            if (viewMenu != null)
            {
                foreach (var item in viewMenu.Where(item => item.Name == "Toolbox"))
                {
                    viewMenu.Children.Remove(item);
                    break;
                }
            }

#if EDITOR
            try
            {
                var rarUri     = Path.Combine(MCFireDirectories.Install, "Resources", "SampleWorld.rar");
                var rarDir     = new Uri(rarUri).LocalPath;
                var extractDir = Path.Combine(MCFireDirectories.MCFireAppdata, "SampleWorld");

                try
                {
                    Directory.Delete(extractDir, true);
                }
                catch (DirectoryNotFoundException) { }
                RarArchive.WriteToDirectory(rarDir, MCFireDirectories.MCFireAppdata, ExtractOptions.ExtractFullPath);
                var sampleInstall = Installation.New(extractDir);
                if (sampleInstall != null)
                {
                    _explorerService.TryAddInstallation(sampleInstall);
                }
                if (sampleInstall == null)
                {
                    return;
                }
                var world = sampleInstall.Worlds.First();
                if (world == null)
                {
                    return;
                }
                var action = new OpenEditorTo(world, 0);
                IoC.BuildUp(action);
                action.Execute(new ActionExecutionContext());
            }
            // ReSharper disable once EmptyGeneralCatchClause DIRTY HACK
            catch
            {
                Debug.Assert(false);
            }
#endif

#if FIRSTRUN || !DEBUG
            if (!Settings.Default.FirstRun)
            {
                return;
            }
            await Task.Delay(1000);

            _overlayService.TrySetOverlay <ConfigureInstallationsViewModel>();
#endif
        }
Beispiel #9
0
        internal void OK_ClickLogic()
        {
            /* Ok button event will:
             * - Go through every folder in the path
             * - Extract every ".rar" file in every folder
             * - Moves all the subs (".srt") files into path
             * - If a file >=100 M then move it to path
             * - Return a log file and message with names of folder that no file was moved from them
             */

            // Begin:Add the last path entered to memory

            Settings.Default.LastPath = Variables.path;
            Settings.Default.Save();

            // End
            Cursor.Current = Cursors.WaitCursor;                                                                        //Changes the cursor to waiting
            string logFileName = Variables.path + "\\logfile_" + DateTime.Now.ToString("dd-MM-yyyy_hh-mm-ss") + ".txt"; //Log file name

            try                                                                                                         // Catches the error that happenes when no path is given by the user before OK buttone is clicked
            {
                using (StreamWriter log = File.CreateText(logFileName))                                                 // Creates a new text file
                {
                    log.WriteLine("Log File {0}", DateTime.Now.ToString("dd-MM-yyyy_hh-mm-ss"));                        // Log file begin
                    log.WriteLine();
                }

                int counter = 0;

                List <string> messageLog = new List <string>();                                           //Creation of list that will store the names of folders that did not contained large videos

                var folders = Directory.GetDirectories(Variables.path, "*", SearchOption.AllDirectories); //Gets the directories list of the path

                //Begin: RAR files extract

                string[] rarFile = new string[100]; //Could be only 100 RAR files maximum in each folder
                foreach (var folder in folders)
                {
                    rarFile = Directory.GetFiles(folder, "*.rar", SearchOption.AllDirectories);
                    if (rarFile.Length != 0) // Do only if RAR files exist in the folder
                    {
                        string destination = folder;
                        try
                        {
                            RarArchive.WriteToDirectory(rarFile[0], destination, NUnrar.Common.ExtractOptions.Overwrite);
                        }
                        catch (System.IO.FileNotFoundException)
                        {
                        }
                    }

                    Array.Clear(rarFile, 0, rarFile.Length);
                }

                //End

                //Begin: Moves all the large videos and subs (.srt) to path

                int df = 0;
                foreach (var folder in folders)
                {
                    DirectoryInfo size  = new DirectoryInfo(folder); // Makes reference to directory
                    FileInfo[]    fiArr = size.GetFiles();           // Get reference to each file in that directory

                    foreach (FileInfo fi in fiArr)
                    {
                        if (fi.Extension == ".srt")
                        {
                            if (!File.Exists(Variables.path + "\\" + fi.Name))
                            {
                                File.Move(fi.FullName, Variables.path + "\\" + fi.Name); // Moves subs (.srt) to path
                            }
                            else
                            {
                                df++;
                                File.Move(fi.FullName, Variables.path + "\\" + df + fi.Name);
                            }
                        }

                        else
                        {
                            if ((fi.Length / 1000000 > 100) && (fi.Extension != ".rar"))
                            {
                                if (!File.Exists(Variables.path + "\\" + fi.Name))
                                {
                                    File.Move(fi.FullName, Variables.path + "\\" + fi.Name);
                                    counter++; // Provides a count of moved files from each folder
                                }
                                else
                                {
                                    df++;
                                    File.Move(fi.FullName, Variables.path + "\\" + df + fi.Name);
                                    counter++;
                                }
                            }
                        }
                    }

                    switch (counter)
                    {
                    case 0:
                        using (StreamWriter log = new StreamWriter(logFileName, true))
                        {
                            log.WriteLine("The folder {0} does not contain any large files", Path.GetFileName(folder));
                            messageLog.Add(Path.GetFileName(folder));     //Adds the names of the folders that have not contained large videos to the log file
                        }
                        break;
                    }

                    if (counter >= 2)
                    {
                        using (StreamWriter log = new StreamWriter(logFileName, true))
                        {
                            log.WriteLine("The folder {0} contained more then one large file", Path.GetFileName(folder));
                        }
                    }

                    counter = 0;
                }

                using (StreamWriter log = new StreamWriter(logFileName, true))
                {
                    log.WriteLine();
                    log.Write("End of the log file");
                }

                ReadOnly rA = new ReadOnly();
                rA.RA();

                //Begin: Show the user all the folder that no file was moved from them in the message box

                StringBuilder builder = new StringBuilder();
                foreach (string mL in messageLog)
                {
                    builder.Append(mL.ToString()).AppendLine();
                }
                Cursor.Current = Cursors.Default; //Returns the cursor to defoult

                if (builder.Length != 0)
                {
                    MessageBox.Show("Warning! \n" + "Following folders did not contain videos: \n" + builder.ToString(), "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    MessageBox.Show("The operationd was finished successfully!", "Cedo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                //End

                // Begin: Folder deletion section

                if (MessageBox.Show("Do you want to delete all the folders in the path?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    var delFolders = Directory.GetDirectories(Variables.path, "*", SearchOption.TopDirectoryOnly); //Gets the directories list of the path top directoy only
                    foreach (var delFolder in delFolders)
                    {
                        try
                        {
                            Directory.Delete(delFolder, true);
                        }
                        catch (IOException e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                }

                //End

                Application.Exit();
            }

            catch (System.UnauthorizedAccessException)
            {
                MessageBox.Show("Please enter a valid path.", "Warning");
            }
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            isDownloading = true;
            this.remove.Dispatcher.BeginInvoke(DispatcherPriority.Send,
                                               (Action)(() => { remove.IsEnabled = false; }));
            HandleXnaVersion();

            if (isConnected == false)
            {
                MessageBox.Show("No Internet Connection");
                return;
            }

            try
            {
                String sitem = listBox1.SelectedItem as String;
                if (String.IsNullOrEmpty(sitem))
                {
                    MessageBox.Show("You Must select a version");
                    this.remove.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                       (Action)(() => { remove.IsEnabled = true; }));
                    isDownloading = false;
                    return;
                }
                if (sitem != packageName)
                {
                    if (!String.IsNullOrEmpty(packageName))
                    {
                        DeleteCurrentEngineVersion();
                        GetVersionOnRegistry();
                        if (!String.IsNullOrEmpty(packageName))
                        {
                            MessageBox.Show("You need to unistall current version to be able to install another");
                            this.remove.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                               (Action)(() => { remove.IsEnabled = true; }));
                            isDownloading = false;
                            return;
                        }
                    }
                    Random rd    = new Random();
                    int    rdnum = rd.Next();

                    button1.IsEnabled  = false;
                    progressBar1.Value = 0;

                    label2.Content = "Downloading";
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            FTP ftp = new FTP("ftp.ploobs.com.br", "ploobs", "5ruTrus6");
                            ftp.Connect();
                            ftp.ChangeDir("/ploobs/Web/Updater/" + sitem);
                            String temppath = System.IO.Path.GetTempPath() + System.IO.Path.GetRandomFileName();
                            ftp.OpenDownload("PloobsEngine.rar", temppath, true);


                            while (ftp.DoDownload() != 0)
                            {
                                progressBar1.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                                    (Action)(() => { progressBar1.Value = 100 * (float)ftp.BytesTotal / (float)ftp.FileSize; }));
                            }

                            label2.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                          (Action)(() => { label2.Content = "INSTALLING"; }));


                            if (File.Exists(System.IO.Path.GetTempPath() + "PloobsEngine//setup.exe"))
                            {
                                File.Delete(System.IO.Path.GetTempPath() + "PloobsEngine//setup.exe");
                            }

                            if (Directory.Exists(System.IO.Path.GetTempPath() + "PloobsEngine/"))
                            {
                                Directory.Delete(System.IO.Path.GetTempPath() + "PloobsEngine/", true);
                            }

                            RarArchive.WriteToDirectory(temppath, System.IO.Path.GetTempPath(), NUnrar.Common.ExtractOptions.ExtractFullPath);

                            temppath = System.IO.Path.GetTempPath() + "PloobsEngine//setup.exe";

                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo.FileName         = temppath;
                            process.Start();
                            process.WaitForExit();

                            packageName = sitem;
                            GetVersionOnRegistry();

                            label2.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                          (Action)(() => { label2.Content = "Current Version: " + packageName; }));


                            MySqlCommonConnection.WriteClientToDB(sitem);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                            label2.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                          (Action)(() => { label2.Content = "ERROR"; }));
                        }
                        finally
                        {
                            button1.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                           (Action)(() => { button1.IsEnabled = true; }));

                            if (packageName != null)
                            {
                                label2.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                              (Action)(() => { label2.Content = "CurrentVersion: " + packageName; }));
                            }
                        }
                    }
                                          );
                }
                else
                {
                    MessageBox.Show("You already have this version installed, Unistall it first clicking on Remove Current Version");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            isDownloading = false;
            this.remove.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                               (Action)(() => { remove.IsEnabled = true; }));
        }