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