now checking for file names rather than using indexes on dir refresh
This commit is contained in:
+24
-16
@@ -51,10 +51,7 @@ unsigned int btm_status;
|
|||||||
|
|
||||||
|
|
||||||
void *thread_mid(){
|
void *thread_mid(){
|
||||||
dir tmp;
|
dir previous_dir_state = { 0 };
|
||||||
tmp.current_file = NULL;
|
|
||||||
tmp.file_list = NULL;
|
|
||||||
tmp.file_count = 0;
|
|
||||||
|
|
||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
|
|
||||||
@@ -74,7 +71,7 @@ void *thread_mid(){
|
|||||||
if (status & STATUS_RELOAD_DIRECTORY) {
|
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||||
long index = mid_dir.current_file - mid_dir.file_list;
|
long index = mid_dir.current_file - mid_dir.file_list;
|
||||||
|
|
||||||
tmp = mid_dir;
|
previous_dir_state = mid_dir;
|
||||||
|
|
||||||
mid_dir.file_count = get_dir_size(path);
|
mid_dir.file_count = get_dir_size(path);
|
||||||
mid_dir.file_list = malloc(mid_dir.file_count * sizeof(file));
|
mid_dir.file_list = malloc(mid_dir.file_count * sizeof(file));
|
||||||
@@ -88,8 +85,21 @@ void *thread_mid(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
for(i = 0; i < mid_dir.file_count && i < tmp.file_count; i++) {
|
for(i = 0; i < mid_dir.file_count && i < previous_dir_state.file_count; i++) {
|
||||||
mid_dir.file_list[i].status = tmp.file_list[i].status;
|
mid_dir.file_list[i].status = previous_dir_state.file_list[i].status;
|
||||||
|
}
|
||||||
|
/* youd think that after the above previous_dir_state = mid_dir previous_dir_state.current_file is always within the bounds of the file_list,
|
||||||
|
* but no, it fucking is not for some reason
|
||||||
|
* however for some mysterious reason this condition doesnt fail. well it probably does,
|
||||||
|
* but that doesnt matter as it does what its supposed to do:
|
||||||
|
* keep the current file selected after a reload even if the dir contents change like a new file being added */
|
||||||
|
if (previous_dir_state.current_file != NULL && previous_dir_state.current_file < previous_dir_state.file_list + previous_dir_state.file_count) {
|
||||||
|
for (i = 0; i < mid_dir.file_count; i++) {
|
||||||
|
if (strcmp(mid_dir.file_list[i].file_name, previous_dir_state.file_list[index].file_name) == 0) {
|
||||||
|
mid_dir.current_file = &mid_dir.file_list[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -124,17 +134,15 @@ void *thread_mid(){
|
|||||||
pthread_mutex_unlock(&mutex_render);
|
pthread_mutex_unlock(&mutex_render);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
for (i = 0; i < tmp.file_count; i++) {
|
for (i = 0; i < previous_dir_state.file_count; i++) {
|
||||||
free(tmp.file_list[i].file_name);
|
free(previous_dir_state.file_list[i].file_name);
|
||||||
}
|
}
|
||||||
free(tmp.file_list);
|
free(previous_dir_state.file_list);
|
||||||
tmp.current_file = NULL;
|
previous_dir_state.current_file = NULL;
|
||||||
tmp.file_list = NULL;
|
previous_dir_state.file_list = NULL;
|
||||||
tmp.file_count = 0;
|
previous_dir_state.file_count = 0;
|
||||||
|
free(path);
|
||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user