示例#1
0
        /*
         * rar解凍実行関数
         * 引数:strFromFile解凍するrarファイルのパス stToPath 圧縮先のフォルダへのパス
         * 戻り値:bool true処理成功 false処理失敗
         */
        static bool runUnRar(string strFromFile, string strToPath)
        {
            bool success;                          //bool型変数作っとく

            Chilkat.Rar rar = new Chilkat.Rar();   //インスタンス作る
            success = rar.Open(strFromFile);       //開く、インスタンスにファイル名渡す
            if (success != true)
            {
                return(false);
            }
            success = rar.Unrar(strToPath + STR_YEN);//解凍処理
            if (success != true)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
示例#2
0
        /*
         * rar解凍実行関数
         * 引数:strFromFile解凍するrarファイルのパス stToPath 圧縮先のフォルダへのパス
         * 戻り値:bool true処理成功 false処理失敗
         */
        static bool runUnRar( string strFromFile, string strToPath ) 
        {
            bool success;                           //bool型変数作っとく
            Chilkat.Rar rar = new Chilkat.Rar();    //インスタンス作る
            success = rar.Open(strFromFile);       //開く、インスタンスにファイル名渡す
            if (success != true)
            {
                Console.WriteLine(rar.LastErrorText);   //オープン失敗でエラー表示
                return false;
            }
            success = rar.Unrar(strToPath + STR_YEN);//解凍処理
            if (success != true)
            {
                Console.WriteLine(rar.LastErrorText);//解凍失敗 エラーメッセージを表示
                return false;
            }
            else
            {
                return true;
            }

        }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            if (backgroundWorker1 != null)
            {
                while (!backgroundWorker1.CancellationPending && finished == false)
                {
                    int i = 0;
                    backgroundWorker1.ReportProgress(i);

                    //============Variables=========================//
                    string inputfile = input_bestand;

                    string inputfolder = System.IO.Path.GetTempPath() + "\\strips";
                    string outputfile = Path.GetDirectoryName(inputfile) + "\\" + Path.GetFileNameWithoutExtension(inputfile) + ".pdf";

                    i = 20;
                    backgroundWorker1.ReportProgress(i);
                    // Determine whether the directory exists.
                    if (!Directory.Exists(inputfolder))
                    {
                        DirectoryInfo di = Directory.CreateDirectory(inputfolder);
                    }

                    System.IO.DirectoryInfo downloadedMessageInfo = new DirectoryInfo(System.IO.Path.GetTempPath() + "\\strips");

                    foreach (FileInfo file in downloadedMessageInfo.GetFiles())
                    {
                        file.Delete();
                    }
                    foreach (DirectoryInfo dir in downloadedMessageInfo.GetDirectories())
                    {
                        dir.Delete(true);
                    }

                    i = 40;
                    backgroundWorker1.ReportProgress(i);

                    //CBR Unzipping=========================================//
                    Chilkat.Rar rar = new Chilkat.Rar();
                    Chilkat.Zip zip = new Chilkat.Zip();
                    zip.UnlockComponent("ZIPT34MB34N_2E76BEB1p39E");
                    bool rarsuccess;
                    bool zipsucces;

                    rarsuccess = rar.Open(inputfile);
                    if (rarsuccess != true)
                    {
                        zipsucces = zip.OpenZip(inputfile);
                        if (zipsucces != true)
                        {
                            MessageBox.Show(zip.LastErrorText);
                            System.Environment.Exit(1);
                        }
                    }

                    rarsuccess = rar.Unrar(inputfolder);
                    if (rarsuccess != true)
                    {
                        int zipreturn = zip.Unzip(inputfolder);
                        if (zipreturn == -1)
                        {
                            MessageBox.Show(zip.LastErrorText);
                            System.Environment.Exit(1);
                        }

                    }
                    else
                    {

                    }
                    i = 60;
                    backgroundWorker1.ReportProgress(i);

                    string[] folders_all = System.IO.Directory.GetDirectories(inputfolder, "*", System.IO.SearchOption.AllDirectories);

                    string[] plaatjes;
                    if (folders_all.Length == 0)
                    {
                        plaatjes = Directory.GetFiles(inputfolder, "*.jpg");
                    }
                    else
                    {
                        string folder = folders_all[0];
                        plaatjes = Directory.GetFiles(folder, "*.jpg");
                    }

                    PdfDocument doc = new PdfDocument();

                    foreach (string source in plaatjes)
                    {
                        PdfPage page = doc.AddPage();

                        XGraphics xgr = XGraphics.FromPdfPage(page);
                        XImage img = XImage.FromFile(source);

                        xgr.DrawImage(img, 0, 0, 595, 841);

                    }
                    i = 80;
                    backgroundWorker1.ReportProgress(i);

                    doc.Save(outputfile);
                    doc.Close();
                    i = 100;
                    finished = true;
                    backgroundWorker1.ReportProgress(i);
                }
            }
        }