Archived Forum Post

Index of archived forum posts

Question:

Its possible report progress for progress bar while making function CkEncryptFile?

Jun 07 '16 at 09:06

Hi, can i ask one question please?

Its possible report progress for progress bar while making function CkEncryptFile?

this is H file

private: System::Void button_encryptFolder_ItemClick(System::Object^ sender, DevExpress::XtraBars::ItemClickEventArgs^ e) { folderBrowserDialog_encryptZipFolder->ShowDialog(); backgroundWorker_encryptFolder->RunWorkerAsync(); } private: System::Void barButtonItem_encryptZipFolder_ItemClick(System::Object^ sender, DevExpress::XtraBars::ItemClickEventArgs^ e) {

}
private: System::Void backgroundWorker_encryptFolder_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) {
    String^ dirPath = folderBrowserDialog_encryptZipFolder->SelectedPath;
    DirectoryInfo^ dirInfo = gcnew DirectoryInfo(dirPath);
    SearchTree(dirInfo);
}
private: System::Void backgroundWorker_encryptFolder_ProgressChanged(System::Object^  sender, System::ComponentModel::ProgressChangedEventArgs^  e) {
    Datapacket^ dp = dynamic_cast<Datapacket^>(e->UserState);
    bottomText1->Caption = dp->bottomText;
}

and this is function in C file

void ProgramPreSrandu::MyForm::SearchTree(DirectoryInfo ^ root) { System::Threading::Thread::Sleep(.5f); Datapacket^ dp = gcnew Datapacket();

Crypt2^ crypto = gcnew Crypt2();
bool success;
crypto->UnlockComponent("30-day trial");
crypto->CryptAlgorithm = "aes";
crypto->KeyLength = 256;
crypto->SetSecretKeyViaPassword("heslo");

array<DirectoryInfo^>^ subDirs = nullptr;
array<FileInfo^>^ files = nullptr;

try
{
    files = root->GetFiles("*.*");
}
catch (UnauthorizedAccessException^ e)
{
    //Console::WriteLine(e->Message);
}
catch (DirectoryNotFoundException^ e)
{
    //Console::WriteLine(e->Message);
}

if (files != nullptr)
{
    for each (FileInfo^ file in files)
    {
        dp->bottomText = String::Format("File: {0}", file->Name);
        backgroundWorker_encryptFolder->ReportProgress(0, dp);
        success = crypto->CkEncryptFile(file->FullName, String::Format("{0}\\encrypted-{1}", Path::GetDirectoryName(file->FullName), file->Name));
        /*if (!success)
        {
            MessageBox::Show(crypto->LastErrorText);
        }*/
    }
    subDirs = root->GetDirectories();

    for each (DirectoryInfo^ dirs in subDirs)
    {
        SearchTree(dirs);
    }
}

}

Thanks :)


Answer

use put_EventCallbackObject: https://chilkatsoft.com/refdoc/javaCkCrypt2Ref.html


Answer

really dont know how to use this in my code, canyou please make small example for me? many thanks :) soft is writen in C++


Answer

I have done this, how can i use it? i have this error: http://prntscr.com/bde7q5

public ref class MyCrypt2Progress : public CkCrypt2Progress { public: MyCrypt2Progress() { } virtual ~MyCrypt2Progress() { }

    void PercentDone(int pctDone, bool *abort)
    {
        Console::WriteLine(String::Format("Percent done: {0}\%", pctDone));
    }
    void ProgressInfo(const char *name, const char *value)
    {
        Console::WriteLine(String::Format("Progress info. Name: {0}, Value: {1}", marshal_as<String^>(std::string(name)), marshal_as<String^>(std::string(value))));
    }
};

Answer

i have done my own progress method via background workers, for now :)