Esempio n. 1
0
        /// <summary>
        /// import a zipped yml file.
        /// if the file is a plain yml file, the content will be zipped.
        /// shows a dialog to the user to select the file to import
        /// </summary>
        /// <returns></returns>
        public static string ImportWithDialogYMLGz(string ADialogTitle)
        {
            OpenFileDialog DialogOpen = new OpenFileDialog();

            DialogOpen.Filter = Catalog.GetString(
                "Zipped Text file (*.yml.gz)|*.yml.gz|Text file (*.yml)|*.yml");
            DialogOpen.FilterIndex      = 0;
            DialogOpen.RestoreDirectory = true;
            DialogOpen.Title            = ADialogTitle;

            if (DialogOpen.ShowDialog() == DialogResult.OK)
            {
                if (DialogOpen.FileName.ToLower().EndsWith("gz"))
                {
                    FileStream fs     = new FileStream(DialogOpen.FileName, FileMode.Open);
                    byte[]     buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, buffer.Length);
                    fs.Close();
                    return(Convert.ToBase64String(buffer));
                }
                else if (DialogOpen.FileName.ToLower().EndsWith("yml"))
                {
                    TextReader reader  = new StreamReader(DialogOpen.FileName, true);
                    string     ymlData = reader.ReadToEnd();
                    reader.Close();
                    return(PackTools.ZipString(ymlData));
                }
            }

            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// this procedure makes sure that the latest version of the patch tool is being used;
        /// the latest available executable and required dlls are copied to the patch tmp directory
        /// </summary>
        /// <returns>void</returns>
        public void CopyLatestPatchProgram(String APatchDirectory)
        {
            String    remotename;
            ArrayList PatchExecutableFiles;

            PatchExecutableFiles = new ArrayList();
            string binPath = "openpetraorg" + Path.DirectorySeparatorChar + "bin" + FVersionPostFix + Path.DirectorySeparatorChar;

            PatchExecutableFiles.Add(binPath + "Ict.Common.dll");
            PatchExecutableFiles.Add(binPath + "Ict.Common.IO.dll");
            PatchExecutableFiles.Add(binPath + "ICSharpCode.SharpZipLib.dll");
            PatchExecutableFiles.Add(binPath + "Ict.Tools.PatchTool.exe");
            PatchExecutableFiles.Add(binPath + "Ict.Tools.PatchTool.Library.dll");
            PatchExecutableFiles.Add(binPath + "GNU.Gettext.dll");

            // copy the PatchTool.exe and required files from the currently installed application to a temp directory
            foreach (string patchExeFile in PatchExecutableFiles)
            {
                if (File.Exists(FBinPath + Path.DirectorySeparatorChar + Path.GetFileName(patchExeFile)))
                {
                    System.IO.File.Copy(FBinPath + Path.DirectorySeparatorChar + Path.GetFileName(patchExeFile),
                                        APatchDirectory + Path.DirectorySeparatorChar + Path.GetFileName(patchExeFile), true);
                }
            }

            // compiling on Linux with Mono, we cannot use the manifest that tells the UAC that running a exe with patch in the name is fine without administrator rights
            // therefore we rename the file so that the normal user can execute it
            string newNameUAC = APatchDirectory + Path.DirectorySeparatorChar + "Ict.Tools.Ptchtool.exe";

            if (File.Exists(newNameUAC))
            {
                File.Delete(newNameUAC);
            }

            File.Move(APatchDirectory + Path.DirectorySeparatorChar + "Ict.Tools.PatchTool.exe", newNameUAC);

            // check for the latest version of those files in the new patches
            foreach (string patch in FListOfNewPatches.GetValueList())
            {
                // download the patch file from the remote server if it is not available locally yet
                // todo: display progress? could do it via the remoting connection?
                if (FRemotePatchesPath.StartsWith("http://") || FRemotePatchesPath.StartsWith("https://"))
                {
                    remotename = FRemotePatchesPath + "/" + Path.GetFileName(patch);
                    THTTPUtils.DownloadFile(remotename, patch);
                }
                else if (!System.IO.File.Exists(patch) && (FRemotePatchesPath.Length > 0))
                {
                    remotename = FRemotePatchesPath + Path.DirectorySeparatorChar + Path.GetFileName(patch);
                    System.IO.File.Copy(remotename, patch);
                }

                PackTools.Unzip(APatchDirectory, patch, PatchExecutableFiles, true);
            }
        }