Comments, don't try to read pattern when creating appdata folder
This commit is contained in:
parent
55a8f32f49
commit
3ff6557f83
@ -24,16 +24,22 @@ constexpr std::array< const wchar_t *, 46 > languages{
|
|||||||
L"hr", L"Croatian", L"ko", L"Korea"
|
L"hr", L"Croatian", L"ko", L"Korea"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// filled with possible season numbers
|
||||||
std::vector< int > options;
|
std::vector< int > options;
|
||||||
|
// contains IDs of checboxes created for IDD_SEASONS
|
||||||
std::vector< int > checkboxes;
|
std::vector< int > checkboxes;
|
||||||
|
// contains season numbers that have been checked in IDD_SEASONS
|
||||||
std::vector< int > checked;
|
std::vector< int > checked;
|
||||||
Curl c;
|
Curl c;
|
||||||
|
|
||||||
wchar_t lang_code[3] = L"en";
|
wchar_t lang_code[3] = L"en";
|
||||||
std::wstring default_pattern = L"%filename - %epname";
|
std::wstring default_pattern = L"%filename - %epname";
|
||||||
|
|
||||||
|
// files separated by season
|
||||||
std::map< int, std::set< string > > files;
|
std::map< int, std::set< string > > files;
|
||||||
|
// possible shows for given query
|
||||||
std::vector< std::pair< string, string > > possible_shows;
|
std::vector< std::pair< string, string > > possible_shows;
|
||||||
|
// files from currently previewed season
|
||||||
std::vector< std::pair< string, std::pair< string, string > > >
|
std::vector< std::pair< string, std::pair< string, string > > >
|
||||||
*current_renamed_files{ nullptr };
|
*current_renamed_files{ nullptr };
|
||||||
|
|
||||||
@ -60,11 +66,13 @@ BOOL CALLBACK SeasonsBox( HWND hwnd, UINT message, WPARAM wParam,
|
|||||||
LPARAM lParam ) {
|
LPARAM lParam ) {
|
||||||
switch ( message ) {
|
switch ( message ) {
|
||||||
case WM_INITDIALOG: {
|
case WM_INITDIALOG: {
|
||||||
|
// fill with checkboxes for possible seasons
|
||||||
checked.clear();
|
checked.clear();
|
||||||
checkboxes.clear();
|
checkboxes.clear();
|
||||||
int left{ 15 }, top{ 30 };
|
int left{ 15 }, top{ 30 };
|
||||||
for ( int i = 0; i < options.size(); i++ ) {
|
for ( int i = 0; i < options.size(); i++ ) {
|
||||||
if ( checkboxes.empty() ) {
|
if ( checkboxes.empty() ) {
|
||||||
|
// start IDs at 2000
|
||||||
checkboxes.push_back( 2000 );
|
checkboxes.push_back( 2000 );
|
||||||
} else {
|
} else {
|
||||||
checkboxes.push_back( checkboxes.back() + 1 );
|
checkboxes.push_back( checkboxes.back() + 1 );
|
||||||
@ -94,6 +102,7 @@ BOOL CALLBACK SeasonsBox( HWND hwnd, UINT message, WPARAM wParam,
|
|||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
switch ( LOWORD( wParam ) ) {
|
switch ( LOWORD( wParam ) ) {
|
||||||
case IDOK:
|
case IDOK:
|
||||||
|
// store checked seasons in checked
|
||||||
for ( int i = 0; i < checkboxes.size(); i++ ) {
|
for ( int i = 0; i < checkboxes.size(); i++ ) {
|
||||||
if ( SendDlgItemMessage( hwnd, checkboxes[i], BM_GETCHECK, 0,
|
if ( SendDlgItemMessage( hwnd, checkboxes[i], BM_GETCHECK, 0,
|
||||||
0 ) )
|
0 ) )
|
||||||
@ -102,11 +111,13 @@ BOOL CALLBACK SeasonsBox( HWND hwnd, UINT message, WPARAM wParam,
|
|||||||
EndDialog( hwnd, 0 );
|
EndDialog( hwnd, 0 );
|
||||||
break;
|
break;
|
||||||
case IDALL:
|
case IDALL:
|
||||||
|
// check all seasons
|
||||||
for ( auto &x : checkboxes ) {
|
for ( auto &x : checkboxes ) {
|
||||||
SendDlgItemMessage( hwnd, x, BM_SETCHECK, BST_CHECKED, 0 );
|
SendDlgItemMessage( hwnd, x, BM_SETCHECK, BST_CHECKED, 0 );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IDNONE:
|
case IDNONE:
|
||||||
|
// uncheck all seasons
|
||||||
for ( auto &x : checkboxes ) {
|
for ( auto &x : checkboxes ) {
|
||||||
SendDlgItemMessage( hwnd, x, BM_SETCHECK, BST_UNCHECKED, 0 );
|
SendDlgItemMessage( hwnd, x, BM_SETCHECK, BST_UNCHECKED, 0 );
|
||||||
}
|
}
|
||||||
@ -124,7 +135,7 @@ BOOL CALLBACK SeasonsBox( HWND hwnd, UINT message, WPARAM wParam,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// stolen from
|
// choose directory, stolen from
|
||||||
// https://www.codeproject.com/Articles/2604/Browse-Folder-dialog-search-folder-and-all-sub-fol
|
// https://www.codeproject.com/Articles/2604/Browse-Folder-dialog-search-folder-and-all-sub-fol
|
||||||
std::wstring getDir() {
|
std::wstring getDir() {
|
||||||
wchar_t path[MAX_PATH];
|
wchar_t path[MAX_PATH];
|
||||||
@ -158,6 +169,7 @@ BOOL CALLBACK PreviewBox( HWND hwnd, UINT message, WPARAM wParam,
|
|||||||
LPARAM lParam ) {
|
LPARAM lParam ) {
|
||||||
switch ( message ) {
|
switch ( message ) {
|
||||||
case WM_INITDIALOG: {
|
case WM_INITDIALOG: {
|
||||||
|
// fill IDTEXT with how the rename would look
|
||||||
std::wstring text{};
|
std::wstring text{};
|
||||||
for ( auto renamed_it = current_renamed_files->begin();
|
for ( auto renamed_it = current_renamed_files->begin();
|
||||||
renamed_it != current_renamed_files->end(); ++renamed_it ) {
|
renamed_it != current_renamed_files->end(); ++renamed_it ) {
|
||||||
@ -189,6 +201,7 @@ BOOL CALLBACK PreviewBox( HWND hwnd, UINT message, WPARAM wParam,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void finishedSelection( HWND hwnd ) {
|
void finishedSelection( HWND hwnd ) {
|
||||||
|
// get show name and url for selected show
|
||||||
auto index = SendDlgItemMessage( hwnd, IDSHOWS, CB_GETCURSEL, 0, 0 );
|
auto index = SendDlgItemMessage( hwnd, IDSHOWS, CB_GETCURSEL, 0, 0 );
|
||||||
auto url = possible_shows[index].second;
|
auto url = possible_shows[index].second;
|
||||||
auto show = possible_shows[index].first;
|
auto show = possible_shows[index].first;
|
||||||
@ -210,15 +223,18 @@ void finishedSelection( HWND hwnd ) {
|
|||||||
false, c, files[x] );
|
false, c, files[x] );
|
||||||
if ( renamed_files.empty() )
|
if ( renamed_files.empty() )
|
||||||
continue;
|
continue;
|
||||||
|
// if user trusts us, just rename files
|
||||||
if ( SendDlgItemMessage( hwnd, IDTRUST, BM_GETCHECK, 0, 0 ) ) {
|
if ( SendDlgItemMessage( hwnd, IDTRUST, BM_GETCHECK, 0, 0 ) ) {
|
||||||
renameFiles( renamed_files );
|
renameFiles( renamed_files );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if user doesn't trust us show what rename would look like
|
||||||
current_renamed_files = &renamed_files;
|
current_renamed_files = &renamed_files;
|
||||||
DialogBox( GetModuleHandle( NULL ), MAKEINTRESOURCE( IDD_PREVIEW ),
|
DialogBox( GetModuleHandle( NULL ), MAKEINTRESOURCE( IDD_PREVIEW ),
|
||||||
hwnd, PreviewBox );
|
hwnd, PreviewBox );
|
||||||
}
|
}
|
||||||
|
// if user trusted us, let them know when rename finished
|
||||||
if ( SendDlgItemMessage( hwnd, IDTRUST, BM_GETCHECK, 0, 0 ) ) {
|
if ( SendDlgItemMessage( hwnd, IDTRUST, BM_GETCHECK, 0, 0 ) ) {
|
||||||
MessageBox( hwnd, L"Finished renaming files", L"Info",
|
MessageBox( hwnd, L"Finished renaming files", L"Info",
|
||||||
MB_OK | MB_ICONINFORMATION );
|
MB_OK | MB_ICONINFORMATION );
|
||||||
@ -245,13 +261,16 @@ void getNames( HWND hwnd ) {
|
|||||||
options.clear();
|
options.clear();
|
||||||
files.clear();
|
files.clear();
|
||||||
|
|
||||||
|
// get possible seasons
|
||||||
iterateFS( files, path );
|
iterateFS( files, path );
|
||||||
for ( auto &x : files ) {
|
for ( auto &x : files ) {
|
||||||
options.push_back( x.first );
|
options.push_back( x.first );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// user selects which seasons should be renamed
|
||||||
DialogBox( GetModuleHandle( NULL ), MAKEINTRESOURCE( IDD_SEASONS ), hwnd,
|
DialogBox( GetModuleHandle( NULL ), MAKEINTRESOURCE( IDD_SEASONS ), hwnd,
|
||||||
SeasonsBox );
|
SeasonsBox );
|
||||||
|
// process selected seasons
|
||||||
finishedSelection( hwnd );
|
finishedSelection( hwnd );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,6 +287,7 @@ void process( HWND hwnd ) {
|
|||||||
wchar_t language[20];
|
wchar_t language[20];
|
||||||
GetDlgItemText( hwnd, IDLANG, language, 20 );
|
GetDlgItemText( hwnd, IDLANG, language, 20 );
|
||||||
|
|
||||||
|
// get language code
|
||||||
for ( int i = 1; i < languages.size(); i += 2 ) {
|
for ( int i = 1; i < languages.size(); i += 2 ) {
|
||||||
if ( !wcscmp( languages[i], language ) ) {
|
if ( !wcscmp( languages[i], language ) ) {
|
||||||
wcscpy_s( lang_code, languages[i - 1] );
|
wcscpy_s( lang_code, languages[i - 1] );
|
||||||
@ -286,14 +306,18 @@ void process( HWND hwnd ) {
|
|||||||
ShowWindow( GetDlgItem( hwnd, IDSHOWS ), SW_SHOW );
|
ShowWindow( GetDlgItem( hwnd, IDSHOWS ), SW_SHOW );
|
||||||
ShowWindow( GetDlgItem( hwnd, IDSEASONS ), SW_SHOW );
|
ShowWindow( GetDlgItem( hwnd, IDSEASONS ), SW_SHOW );
|
||||||
|
|
||||||
|
// fill IDSHOWS with possible shows
|
||||||
SendDlgItemMessage( hwnd, IDSHOWS, CB_RESETCONTENT, 0, 0 );
|
SendDlgItemMessage( hwnd, IDSHOWS, CB_RESETCONTENT, 0, 0 );
|
||||||
for ( int i = 0; i < possible_shows.size(); i++ ) {
|
for ( int i = 0; i < possible_shows.size(); i++ ) {
|
||||||
SendDlgItemMessage( hwnd, IDSHOWS, CB_ADDSTRING, 0,
|
SendDlgItemMessage( hwnd, IDSHOWS, CB_ADDSTRING, 0,
|
||||||
( LPARAM )possible_shows[i].first.c_str() );
|
( LPARAM )possible_shows[i].first.c_str() );
|
||||||
}
|
}
|
||||||
|
// select first item
|
||||||
SendDlgItemMessage( hwnd, IDSHOWS, CB_SETCURSEL, 0, 0 );
|
SendDlgItemMessage( hwnd, IDSHOWS, CB_SETCURSEL, 0, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if stored pattern exists, read it and store the value
|
||||||
|
// in default_pattern
|
||||||
void readDefaultPattern( const string &base_dir ) {
|
void readDefaultPattern( const string &base_dir ) {
|
||||||
std::wifstream file( base_dir + L"\\pattern" );
|
std::wifstream file( base_dir + L"\\pattern" );
|
||||||
if ( file ) {
|
if ( file ) {
|
||||||
@ -304,17 +328,18 @@ void readDefaultPattern( const string &base_dir ) {
|
|||||||
BOOL CALLBACK MainBox( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) {
|
BOOL CALLBACK MainBox( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) {
|
||||||
switch ( message ) {
|
switch ( message ) {
|
||||||
case WM_INITDIALOG: {
|
case WM_INITDIALOG: {
|
||||||
|
// fill IDLANG with possible languages
|
||||||
for ( int i = 1; i < languages.size(); i += 2 ) {
|
for ( int i = 1; i < languages.size(); i += 2 ) {
|
||||||
SendDlgItemMessage( hwnd, IDLANG, CB_ADDSTRING, 0,
|
SendDlgItemMessage( hwnd, IDLANG, CB_ADDSTRING, 0,
|
||||||
( LPARAM )languages[i] );
|
( LPARAM )languages[i] );
|
||||||
}
|
}
|
||||||
|
// select English by default
|
||||||
SendDlgItemMessage( hwnd, IDLANG, CB_SETCURSEL, 5, 0 );
|
SendDlgItemMessage( hwnd, IDLANG, CB_SETCURSEL, 5, 0 );
|
||||||
|
|
||||||
auto appdata = userHome() + L"\\tv_rename";
|
auto appdata = userHome() + L"\\tv_rename";
|
||||||
if ( !FSLib::isDirectory( appdata ) ) {
|
if ( !FSLib::isDirectory( appdata ) ) {
|
||||||
if ( CreateDirectory( appdata.c_str(), NULL ) ) {
|
// create the directory so pattern can be stored when changed
|
||||||
readDefaultPattern( appdata );
|
CreateDirectory( appdata.c_str(), NULL );
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
readDefaultPattern( appdata );
|
readDefaultPattern( appdata );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user