Добавлен режим "ТОХА". В этом режиме, при вставке пути к патенту, из этого пути выдирается номер патента и в дальнейшем используется в имени папки, где он будет сохранен.
Нормальный режим - нормальный режим.
ФоруМ БМТ |
Привет, Гость! Войдите или зарегистрируйтесь.
Добавлен режим "ТОХА". В этом режиме, при вставке пути к патенту, из этого пути выдирается номер патента и в дальнейшем используется в имени папки, где он будет сохранен.
Нормальный режим - нормальный режим.
Кому интересно - исходник.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include "main_unit.h"
#include "SysUtils.hpp"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int ind,PageCounter=0;
int ArrInd[2048];
AnsiString ArrNames[2048];
int FileNumber=0;//,BufferNaOtkritie=0;
AnsiString ImyaFayla, ImyaFaylaSet ="";
void PoiskSlasha(AnsiString Slash);
void PoiskSlasha(AnsiString Slash)
{
int Pos = Form1->Edit1->Text.Pos(Slash);
while (Pos != 0)
{
AnsiString TempText = Form1->Edit1->Text.SubString(1,Pos-1) + " " + Form1->Edit1->Text.SubString(Pos+1, Form1->Edit1->Text.Length());
Pos = Form1->Edit1->Text.Pos(Slash);
Form1->Edit1->Text = TempText;
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ArrInd[0]=0;
if (Edit1->Text == "")
{
ShowMessage("Ââåäèòå íàçâàíèå ïàòåíòà");
return;
}
PoiskSlasha("/");
PoiskSlasha("\\");
PoiskSlasha(":");
PoiskSlasha("*");
PoiskSlasha("?");
PoiskSlasha("'");
PoiskSlasha("<");
PoiskSlasha(">");
PoiskSlasha("|");
PoiskSlasha('"');
Edit1->Text = Trim(Edit1->Text);
//Edit3->Text=Edit1->Text;
FILE *Spisok;
if ((Spisok = fopen(ImyaFayla.c_str(), "a+")) == NULL)
{
ShowMessage("Ñîçäàéòå íîâûé ñïèñîê èëè îòêðîéòå ñîõðàíåííûé");
return;
}
AnsiString VarR, Nachalka, Konec, Zamenyalka, Vstavlyalka;
VarR = Form1->LabeledEdit1->Text;
if (VarR.Pos(Form1->Edit2->Text) == 0)
{
Application->MessageBoxA("Ïðîâåðü, åñòü ëè òî, ÷òî ÿ èùó â ñòðîêå àäðåñà!", "Êîñÿ÷îêñ!", MB_OK + MB_TOPMOST);
}
else
{
VarR = Form1->LabeledEdit1->Text;
Nachalka = VarR.SubString(1,VarR.Pos(Form1->Edit2->Text)-1);
Konec = VarR.SubString(VarR.Pos(Form1->Edit2->Text)+Form1->Edit2->Text.Length(),VarR.Length());
for (int i = StrToInt(Form1->LabeledEdit2->Text); i<=StrToInt(Form1->LabeledEdit3->Text);i++)
{
PageCounter++;
Zamenyalka = Form1->Edit2->Text.SubString(1,Form1->Edit2->Text.Length()-1);
Vstavlyalka = Nachalka + Zamenyalka + IntToStr(i) + Konec + "\n";
fprintf(Spisok, Vstavlyalka.c_str());
}
fclose(Spisok);
//Form1->Label8->Caption = "Ùàñ ìîæíî íà÷àòü çàêà÷êó";
ind++;
ArrInd[ind]=ArrInd[ind-1]+StrToInt(LabeledEdit3->Text)-StrToInt(LabeledEdit2->Text)+1;//+BufferNaOtkritie;
ArrNames[ind]=Edit1->Text;
FILE *SpisokSetings;
if ((SpisokSetings = fopen(ImyaFaylaSet.c_str(), "a+")) == NULL)
{
ShowMessage("Íå ìîãó îòêðûòü ôàéë äëÿ õðàíåíèÿ íàñòðîåê");
return;
}
fprintf(SpisokSetings, "%i %s\n", ArrInd[ind], ArrNames[ind]);
fclose(SpisokSetings);
Form1->Label7->Caption = "Âñåãî ïàòåíòîâ â ñïèñêå " + IntToStr(ind) + ", êîòîðûå ñîäåðæàò " + IntToStr(ArrInd[ind]) + " ñòðàíèö.";
Label14->Caption = IntToStr(ind);
Label15->Caption = IntToStr(ArrInd[ind]);
LabeledEdit1->Text="";
Edit1->Text = "";
Form1->Button2->Enabled = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
FormStyle = fsStayOnTop;
if ((Dannie = fopen((GetCurrentDir() + "\\SpisokFilov.txt").c_str(), "wt+")) == NULL)
{
ShowMessage("Íå óäàåòñÿ ñîçäàòü ôàéë äëÿ ñîõðàíåíèÿ ñïèñêîâ");
return;
}
fclose(Dannie); */
Form1->Edit3->Text = (GetCurrentDir()+"\\");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{ TSearchRec srF;
int iAttFiles = 0;
iAttFiles |= faAnyFile;
if (FindFirst((GetCurrentDir()+ "\\TempDownloads\\." + Form1->Edit4->Text), iAttFiles, srF) == 0)
{ if ((srF.Attr & iAttFiles) == srF.Attr)
{
if (RenameFile(GetCurrentDir()+ "\\TempDownloads\\" + srF.Name, GetCurrentDir()+ "\\TempDownloads\\" + "(0)." + Form1->Edit4->Text) == false)
{
Application->MessageBoxA("Íå ìîãó ïåðåèìåíîâàòü íóëåâîé ôàéëèê ", "Êîñÿ÷îêñ...", MB_OK + MB_TOPMOST);
}
}
FindClose(srF); //Ê ïåðâîìó ôàéëó äîáàâëÿåì íîëèê
}
bool flag = false;
FileNumber=0;
for (int i = 1; i <= ind; i++)
{
AnsiString Katalog = Form1->Edit3->Text + ArrNames[i];
AnsiString NewFileName;
flag = false;
if (CreateDir(Katalog) == false)
{ /*AnsiString Messaga = "Íå ìîãó ñîçäàòü ïàïêó " + ArrNames[i] + ".\n Åé áóäåò ïðèñâîèíî ñëåäóþùåå èìÿ: " + ArrNames[i] + IntToStr(i);
Application->MessageBoxA(Messaga.c_str(), "Íåáîëüøîé êîñÿ÷îêñ...", MB_OK + MB_TOPMOST);
//flag = true;
Katalog = Form1->Edit3->Text + ArrNames[i] + IntToStr(i);
if (CreateDir(Katalog) == false)
{ */
unsigned short H,M,S,MS;
DecodeTime(Time(),H,M,S,MS);
AnsiString Messaga = "Íå ìîãó ñîçäàòü ïàïêó " + ArrNames[i] + IntToStr(i) + ".\n Åé áóäåò ïðèñâîèíî ñëåäóþùåå èìÿ: " + ArrNames[i] + IntToStr(MS);
Application->MessageBoxA(Messaga.c_str(), "Âòîðîé íåáîëüøîé êîñÿ÷îêñ...", MB_OK + MB_TOPMOST);
Katalog = Form1->Edit3->Text + ArrNames[i] + IntToStr(MS);
if (CreateDir(Katalog) == false)
{
Application->MessageBoxA("Äà Âû, áàòåíüêà, ñîâñåì îôèãåëè!\nÍå ìîãó ñîçäàòü êàòàëîã è âñå-òóò! Åñëè òû ýòî âèäèøü - çâîíè m_dekan'ó", "Âòîðîé íåáîëüøîé êîñÿ÷îêñ...", MB_OK + MB_TOPMOST);
}
}
for (int couRR = 0; couRR < ArrInd[i]-ArrInd[i-1]; couRR++)
{
if (FindFirst((GetCurrentDir()+ "\\TempDownloads\\*(" + IntToStr(FileNumber) + ")." + Form1->Edit4->Text), iAttFiles, srF) == 0)
{
if ((srF.Attr & iAttFiles) == srF.Attr)
{
FileNumber++;
NewFileName = ChangeFileExt(srF.Name,".tiff");
AnsiString NewPath = Katalog + "\\" + NewFileName;
if (RenameFile(GetCurrentDir()+ "\\TempDownloads\\" + srF.Name, NewPath) == false)
{
Application->MessageBoxA("Íå ìîãó êîïèðîâàòü èëè ïåðåèìåíîâàòü ïàòåíò ", "Êîñÿ÷îêñ...", MB_OK + MB_TOPMOST);
flag = true;
}
}
}
}
// }
//}
}
if (flag == false)
{
Form1->LabeledEdit1->Text = "";
Form1->Edit1->Text = "";
ind =0;
PageCounter=0;
FileNumber=0;
for (int i = 0; i <2048; i++)
{
ArrInd[i] = 0;
ArrNames[i] = "";
}
Form1->Button2->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
//Form1->Label7->Caption = Form1->Edit1->Text;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if (FormStyle == fsStayOnTop)
{
Button3->Caption = "Âêëþ÷èòü 'Ïîâåðõ âñåõ'";
FormStyle = fsNormal;
}
else
{
Button3->Caption = "Âûêëþ÷èòü 'Ïîâåðõ âñåõ'";
FormStyle = fsStayOnTop;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
if (SaveDialog1->Execute() == true)
{
Label5->Caption = "";
Label7->Caption = "";
Label14->Caption = "0";
Label15->Caption = "0";
Button1->Enabled=true;
// BufferNaOtkritie=0;
ImyaFayla = SaveDialog1->FileName;
for (int i = 0; i <2048; i++)
{
ArrInd[i] = 0;
ArrNames[i] = "";
}
ind =0;
PageCounter=0;
FileNumber=0;
if (ImyaFayla.Pos(".txt") == 0)
{
ImyaFaylaSet = ImyaFayla + "Set.fuck";
ImyaFayla = ImyaFayla + ".txt";
}
else
{
ImyaFaylaSet = ImyaFayla.SubString(1,ImyaFayla.Length()-4) + "Set.fuck";
}
FILE *SpisokSetings;
if ((SpisokSetings = fopen(ImyaFaylaSet.c_str(), "w+")) == NULL)
{
ShowMessage("Íå ìîãó ñîçäàòü ôàéë äëÿ õðàíåíèÿ íàñòðîåê");
return;
}
fclose(SpisokSetings);
if ((SpisokSetings = fopen(ImyaFayla.c_str(), "w+")) == NULL)
{
ShowMessage("Íå ìîãó ñîçäàòü ôàéë äëÿ õðàíåíèÿ ïóòåé ê ïàòåíòàì");
return;
}
fclose(SpisokSetings);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
/*if (Application->MessageBoxA("Îòêðûòèå íîâîãî ñïèñêà óäàëèò ðåäàêòèðóåìûé. Óâåðåí?",
"Ñëåäè çà ñîáîé... Áóäü îñòîðîæåí",
MB_YESNO + MB_ICONQUESTION) == IDYES)
{
*/
if (OpenDialog1->Execute() == true)
{
//ind =0;
Button2->Enabled=true;
Button1->Enabled=true;
Label14->Caption="0";
Label15->Caption="0";
PageCounter=0;
FileNumber=0;
for (int i = 0; i <2048; i++)
{
ArrInd[i] = 0;
ArrNames[i] = "";
}
ImyaFayla=OpenDialog1->FileName;
if (ImyaFayla.Pos(".txt") != 0)
{
ImyaFaylaSet = ImyaFayla.SubString(1,ImyaFayla.Length()-4) + "Set.fuck";
}
TStringList *List = new TStringList;
try {
List->LoadFromFile(ImyaFaylaSet);}
catch (...){ ShowMessage("Íå ìîãó îòêðûòü ôàéë äëÿ ÷òåíèÿ íàñòðîåê");}
//int f;
for (ind =1; ind <= List->Count; ind++)
{
try{
ArrInd[ind] = StrToInt(List->Strings[ind-1].SubString(1, List->Strings[ind-1].Pos(" ")-1));
ArrNames[ind] = List->Strings[ind-1].SubString(List->Strings[ind-1].Pos(" ")+1,List->Strings[ind-1].Length());
}
__finally{};
}
//int d = 0;
Label5->Caption = "Ïåðâûé ïàòåíò â ýòîì ñïèñêå: " + ArrNames[1].SubString(1,30) + "...";
Label7->Caption = "Âñåãî ïàòåíòîâ â ñïèñêå " + IntToStr(List->Count) + ", êîòîðûå ñîäåðæàò " + ArrInd[List->Count] + " ñòðàíèö.";
// BufferNaOtkritie= ArrInd[List->Count];
ind = List->Count;
}
//}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LabeledEdit1Change(TObject *Sender)
{
if (RadioButton2->Checked == true)
{ int NumPat = LabeledEdit1->Text.Pos("US");
if ( NumPat != 0)
{
Edit1->Text = LabeledEdit1->Text.SubString(NumPat+2,3) + ","
+ LabeledEdit1->Text.SubString(NumPat+5,3)
+ "," + LabeledEdit1->Text.SubString(NumPat+8,3);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
Form2->Visible=true;
}
//---------------------------------------------------------------------------
И вторая форма:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "main_unit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
int coun=0;
void PoiskPapok(AnsiString Path);
void ListFiles(AnsiString path);
//---------------------------------------------------------------------------
void ListFiles(AnsiString path)
{
// Ýòà ïðîöåäóðà âûâîäèò ñïèñîê ôàéëîâ è âûçûâàåò
// ñàìó ñåáÿ äëÿ âñåõ êàòàëîãîâ
TSearchRec sr;
if (FindFirst(path + "\\*.*", faAnyFile, sr) == 0)
{
do
{
if (sr.Attr & faDirectory)
{
if (sr.Name!=".")
if (sr.Name!="..")
{
ListFiles(path+"\\"+sr.Name+"\\");// Ðåêóðñèâíûé âûçîâ
}
}
else
{
//nsiString Ext=ExtractFileExt(sr.Name);
//if (Ext==".txt")
//List->Add(path+sr.Name);
coun++;
AnsiString NewPath;
if (sr.Name == ".tiff")
{
if (RenameFile(path+ "\\" + sr.Name, path+ "\\(0).tiff") == false)
{
Application->MessageBoxA("Íå ìîãó ïåðåèìåíîâàòü íóëåâîé ôàéëèê ", "Êîñÿ÷îêñ...", MB_OK + MB_TOPMOST);
}
else {sr.Name = "(0).tiff";}
}
AnsiString Ext=ExtractFileExt(sr.Name).UpperCase();
if (Ext==".TIFF")
{
switch( sr.Name.Pos(")") )
{
case 3 :{NewPath = path+ "\\" + "000" + sr.Name.SubString(2,1) + sr.Name.SubString(4,sr.Name.Length());
break;
}
case 4 :{NewPath = path+ "\\" + "00" + sr.Name.SubString(2,2) + sr.Name.SubString(5,sr.Name.Length());
break;
}
case 5 :{NewPath = path+ "\\" + "0" + sr.Name.SubString(2,3) + sr.Name.SubString(6,sr.Name.Length());
break;
}
case 6 :{NewPath = path+ "\\" + sr.Name;
break;
}
}
if (RenameFile(path+ "\\" + sr.Name, NewPath) == false)
{
//Application->MessageBoxA("Íå ìîãó êîïèðîâàòü èëè ïåðåèìåíîâàòü ïàòåíò ", "Êîñÿ÷îêñ...", MB_OK + MB_TOPMOST);
//flag = true;
}
}
}
}
while (FindNext(sr) == 0);
FindClose(sr);
}
//pplication->ProcessMessages();
}
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{ coun=0;
//PoiskPapok(Form2->DirectoryListBox1->Directory);
ListFiles(DirectoryListBox1->Directory);
Application->MessageBoxA(IntToStr(coun).c_str(),"Âñåãî ôàéëîâ", MB_OK);
}
//---------------------------------------------------------------------------