示例#1
0
        private void BtImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            dialog.DefaultExt       = ".zip"; // Default file extension
            dialog.Filter           = "zip files (*.zip)|*.zip|All files (*.*)|*.*";
            dialog.FileName         = MyConfig.GetSetting(MyConfig.Key_StudentHash) + ".zip";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string fileName = dialog.FileName;
                if (!File.Exists(fileName))
                {
                    MessageBox.Show(fileName, "File NOT Found");
                    return;
                }

                string userFolder = MyFileHelper.GetUserfolderPath();

                DialogResult dialogResult =
                    MessageBox.Show("This will overwrite existing exercise files. Continue?",
                                    "Import Profile", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (dialogResult == DialogResult.No)
                {
                    return;
                }

                ZipArchiveExtensions.ExtractZipFileToDirectory(fileName, userFolder, true);

                Application.Restart();
            }
        }
示例#2
0
 public static int ExtractToDirectory(
     this ZipArchive archive,
     string destinationDirectoryName,
     bool overwrite,
     Button b,
     ProgressBar pBar)
 {
     if (!overwrite)
     {
         archive.ExtractToDirectory(destinationDirectoryName);
         return(0);
     }
     foreach (ZipArchiveEntry entry in archive.Entries)
     {
         ++ZipArchiveExtensions.entryAmount;
     }
     try
     {
         pBar.Maximum = ZipArchiveExtensions.entryAmount;
     }
     catch (Exception ex)
     {
     }
     foreach (ZipArchiveEntry entry in archive.Entries)
     {
         string str = Path.Combine(destinationDirectoryName, entry.FullName);
         if (entry.Name == "")
         {
             Directory.CreateDirectory(Path.GetDirectoryName(str));
             ++ZipArchiveExtensions.entryExtractedAmount;
             ZipArchiveExtensions.updateButtonAndBar(b, pBar);
         }
         else
         {
             if (!Directory.Exists(Path.GetDirectoryName(str)) && Path.GetDirectoryName(str) != "")
             {
                 Directory.CreateDirectory(Path.GetDirectoryName(str));
             }
             try
             {
                 entry.ExtractToFile(str, true);
                 ++ZipArchiveExtensions.entryExtractedAmount;
             }
             catch (IOException ex)
             {
                 int num = (int)MessageBox.Show("Another process is using \"" + str + "\".\nMake sure Team Fortress 2 Classic is closed while updating the game. There could possibly be other processes using the file.", "An error occurred while updating the game!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                 return(1);
             }
             ZipArchiveExtensions.updateButtonAndBar(b, pBar);
         }
     }
     return(0);
 }
示例#3
0
 private void Form1_Shown(object sender, EventArgs e)
 {
     Task.Run(() =>
     {
         if (File.Exists(downloadFile))
         {
             try
             {
                 ZipArchive zip = new ZipArchive(new MemoryStream(File.ReadAllBytes(downloadFile)));
                 ZipArchiveExtensions.ExtractToDirectory(zip, extractLocation, true);
                 File.Delete(downloadFile);
             }
             catch (Exception ex)
             {
             }
             var process = new Process
             {
                 StartInfo = new ProcessStartInfo
                 {
                     FileName = startAfter
                                // Arguments = string.Join(" ", Environment.GetCommandLineArgs())
                 }
             };
             process.Start();
             process.WaitForInputIdle();
             Application.Exit();
             Environment.Exit(0);
         }
         else
         {
             var process = new Process
             {
                 StartInfo = new ProcessStartInfo
                 {
                     FileName = startAfter
                                // Arguments = string.Join(" ", Environment.GetCommandLineArgs())
                 }
             };
             process.Start();
             process.WaitForInputIdle();
             Application.Exit();
             Environment.Exit(0);
         }
     });
 }
示例#4
0
        //Referencing Zip code from
        //https://github.com/projectkudu/kudu/blob/Kudu.Services/Diagnostics/DiagnosticsController.cs
        public HttpResponseMessage Get(string sessionId, string downloadableFileType, string diagnoserName)
        {
            var pathslist = new List <DaaSFileInfo>();

            PopulateFileList(pathslist, sessionId, downloadableFileType, diagnoserName);
            var response = new HttpResponseMessage(HttpStatusCode.OK);

            if (pathslist.Count > 1 || downloadableFileType == "MemoryDumps")
            {
                response.Content = ZipStreamContent.Create(
                    String.Format("{0}-{1}-{2}.zip", sessionId, diagnoserName, downloadableFileType),
                    zip =>
                {
                    ZipArchiveExtensions.AddFilesToZip(pathslist, zip);
                });
            }
            else if (pathslist.Count == 0)
            {
                string html = @"<B>DaaS Session Error:</B>
                            <BR/>No files are present. 
                            <BR/>Please try again later if the session is still in progress.
                            <BR/>Please invoke a new session if the session is not in progress.";

                response.Content = new StringContent(html);
                response.Content.Headers.ContentType                 = new MediaTypeHeaderValue("application/html");
                response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
                response.Content.Headers.ContentDisposition.FileName = "nofiles.html";
            }
            else
            {
                response.Content = new StreamContent(
                    new FileStream(pathslist[0].FilePath, FileMode.Open)
                    );
                FileInfo fi = new FileInfo(pathslist[0].FilePath);
                response.Content.Headers.ContentType                 = new MediaTypeHeaderValue("application/html");
                response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
                response.Content.Headers.ContentDisposition.FileName = String.Concat(pathslist[0].Prefix, fi.Name);
            }
            return(response);
        }
示例#5
0
        private void timer_update_Tick(object sender, EventArgs e)
        {
            string[] updateDownload;
            using (var wc = new WebClient())
                updateDownload = wc.DownloadString(ini.IniReadValue("VERSION", "UpdateDownloadUrl")).Split(new[] { '\r', '\n' });

            if (!Directory.Exists(tempFolder))
            {
                Directory.CreateDirectory(tempFolder);
                lbl_action.Text = "Create temp download folder";
            }
            string zip_path = tempFolder + "\\" + Guid.NewGuid() + ".zip";

            updateActionLabel("Downloading update");
            using (WebClient wc = new WebClient())
            {
                wc.DownloadFile(
                    // download link
                    new Uri(updateDownload[0]),
                    // physical link
                    zip_path
                    );
            }
            updateActionLabel("Extracting files and updating CODEx");

            string install_path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            using (var strm = File.OpenRead(zip_path))
                using (ZipArchive archive = new ZipArchive(strm))
                    ZipArchiveExtensions.ExtractToDirectory(archive, install_path, true);

            updateActionLabel("Updating CODEx config file");
            ini.IniWriteValue("VERSION", "CurrentVersion", new WebClient().DownloadString(ini.IniReadValue("VERSION", "LastestVersionUrl")));
            updateActionLabel("Update is done");
            pnl_loading.Dispose();
            btn_end.Visible = true;
            timer_update.Stop();
        }
示例#6
0
        public DtoModuleResult Run()
        {
            Logger.Info("Running File Copy Module: " + _module.DisplayName);
            if (_module.Destination.Equals("[toec-appdata]"))
            {
                Logger.Debug("Module Has No Destination.  Module Is Cached Only.");
            }
            else
            {
                if (!_fileSystemService.CreateDestinationDirectory(_module.Destination))
                {
                    _moduleResult.Success      = false;
                    _moduleResult.ExitCode     = "-1";
                    _moduleResult.ErrorMessage = "Could Not Create Destination Directory";
                    return(_moduleResult);
                }
            }

            foreach (var file in _module.Files)
            {
                Logger.Debug(string.Format("Processing File {0}", file.FileName));
                if (!File.Exists(Path.Combine(DtoGobalSettings.BaseCachePath, _module.Guid,
                                              file.FileName)))
                {
                    Logger.Debug("File No Longer Exists: " + Path.Combine(DtoGobalSettings.BaseCachePath, _module.Guid,
                                                                          file.FileName));
                    _moduleResult.Success      = false;
                    _moduleResult.ExitCode     = "-1";
                    _moduleResult.ErrorMessage = "The File No Longer Exists.";
                    return(_moduleResult);
                }

                var extension = Path.GetExtension(file.FileName);
                if (_module.Unzip && !string.IsNullOrEmpty(extension) && extension.ToLower().Equals(".zip"))
                {
                    if (_module.Destination.Equals("[toec-appdata]"))
                    {
                        _module.Destination = Path.Combine(DtoGobalSettings.BaseCachePath, _module.Guid);
                    }
                    try
                    {
                        var path = Path.Combine(DtoGobalSettings.BaseCachePath, _module.Guid, file.FileName);
                        using (FileStream zipToOpen = new FileStream(path, FileMode.Open))
                        {
                            using (ZipArchive archive = new ZipArchive(zipToOpen))
                            {
                                ZipArchiveExtensions.ExtractToDirectory(archive, _module.Destination, true);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Could Not Unzip File");
                        Logger.Error(ex.Message);
                        _moduleResult.Success      = false;
                        _moduleResult.ExitCode     = "-1";
                        _moduleResult.ErrorMessage = "Could Not Unzip File To Destination";
                        return(_moduleResult);
                    }
                }
                else if (_module.Destination.Equals("[toec-appdata]"))
                {
                    //do nothing, file was already copied during cacheing
                }
                else
                {
                    if (
                        !_fileSystemService.CopyFile(
                            Path.Combine(DtoGobalSettings.BaseCachePath, _module.Guid, file.FileName),
                            Path.Combine(_module.Destination, file.FileName)))
                    {
                        _moduleResult.Success      = false;
                        _moduleResult.ExitCode     = "-1";
                        _moduleResult.ErrorMessage = "Could Not Copy File To Destination";
                        return(_moduleResult);
                    }
                }
            }

            Logger.Info($"File Copy Module {_module.DisplayName} Completed");
            return(_moduleResult);
        }
示例#7
0
        void Open(FilePath openPath, bool isDirectory, params AgentType [] platformTargets)
        {
            pages.Clear();

            var indexPage = new WorkbookPage(this, platformTargets);

            if (openPath.IsNull)
            {
                WorkingPath = FilePath.Empty;
                AddPage(indexPage);
                return;
            }

            FilePath readPath;

            if (isDirectory)
            {
                indexPage.Path      = indexPageFileName;
                readPath            = openPath.Combine(indexPage.Path);
                openedFromDirectory = true;
            }
            else
            {
                // If we are opening a file within a .workbook directory somewhere,
                // actually open that directory. This is to mostly address issues
                // on Windows where you cannot open a directory via Explorer.
                //
                // FIXME: The file within the workbook directory is intentionally
                // ignored for now, so this will effectively open index.workbook,
                // hitting the 'isDirectory' path above via the recursive Open call.
                // In reality for now it does not matter since we do not support
                // workbooks with multiple pages.
                for (var parentPath = openPath.ParentDirectory;
                     !parentPath.IsNull;
                     parentPath = parentPath.ParentDirectory)
                {
                    if (parentPath.DirectoryExists && parentPath.Extension == dottedExtension)
                    {
                        LogicalPath = parentPath;
                        Open(parentPath, true, platformTargets);
                        return;
                    }
                }

                indexPage.Path = openPath.Name;
                readPath       = openPath;
            }

            using (var stream = new FileStream(
                       readPath,
                       FileMode.Open,
                       FileAccess.Read,
                       FileShare.Read)) {
                if (!isDirectory)
                {
                    if (ZipArchiveExtensions.SmellHeader(stream))
                    {
                        OpenZip(stream, platformTargets);
                        return;
                    }

                    // seek back to start since we just checked for a Zip header
                    stream.Seek(0, SeekOrigin.Begin);
                }

                indexPage.Read(new StreamReader(stream));
            }

            AddPage(indexPage);
            WorkingPath = openPath;
        }