Rewrite another function

This commit is contained in:
twinaphex 2017-09-29 19:09:11 +02:00
parent 1c477ca007
commit 4639b2547d
4 changed files with 45 additions and 22 deletions

View File

@ -592,7 +592,7 @@ static void xui_render(void *data, bool is_idle)
for (i = 0; i < end; i++)
{
menu_entry_t entry;
char entry_path[PATH_MAX_LENGTH] = {0};
char *entry_path = NULL;
char entry_value[PATH_MAX_LENGTH] = {0};
wchar_t msg_right[PATH_MAX_LENGTH] = {0};
wchar_t msg_left[PATH_MAX_LENGTH] = {0};
@ -601,13 +601,15 @@ static void xui_render(void *data, bool is_idle)
menu_entry_get(&entry, 0, i, NULL, true);
menu_entry_get_value(&entry, entry_value, sizeof(entry_value));
menu_entry_get_path(&entry, entry_path, sizeof(entry_path));
entry_path = menu_entry_get_path(&entry);
mbstowcs(msg_left, entry_path, sizeof(msg_left) / sizeof(wchar_t));
mbstowcs(msg_right, entry_value, sizeof(msg_right) / sizeof(wchar_t));
xui_set_list_text(i, msg_left, msg_right);
menu_entry_free(&entry);
if (entry_path && !string_is_empty(entry_path))
free(entry_path);
}
selection = menu_navigation_get_selection();

View File

@ -105,11 +105,11 @@ void menu_entry_init(menu_entry_t *entry)
entry->spacing = 0;
}
void menu_entry_get_path(menu_entry_t *entry, char *s, size_t len)
char *menu_entry_get_path(menu_entry_t *entry)
{
if (!entry)
return;
strlcpy(s, entry->path, len);
if (!entry || string_is_empty(entry->path))
return NULL;
return strdup(entry->path);
}
char *menu_entry_get_rich_label(menu_entry_t *entry)

View File

@ -59,7 +59,7 @@ typedef struct menu_entry
enum menu_entry_type menu_entry_get_type(uint32_t i);
void menu_entry_get_path(menu_entry_t *entry, char *s, size_t len);
char *menu_entry_get_path(menu_entry_t *entry);
void menu_entry_get_label(menu_entry_t *entry, char *s, size_t len);

View File

@ -113,7 +113,7 @@ static void RunActionSheet(const char* title, const struct string_list* items,
{
menu_entry_t entry;
char buffer[PATH_MAX_LENGTH];
char label[PATH_MAX_LENGTH];
char *label = NULL;
static NSString* const cell_id = @"text";
self.parentTable = tableView;
@ -125,17 +125,22 @@ static void RunActionSheet(const char* title, const struct string_list* items,
menu_entry_init(&entry);
menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true);
menu_entry_get_path(&entry, label, sizeof(label));
label = menu_entry_get_path(&entry);
menu_entry_get_value(&entry, buffer, sizeof(buffer));
result.textLabel.text = BOXSTRING(label);
if (string_is_empty(label))
strlcpy(buffer,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE),
sizeof(buffer));
if (label && !string_is_empty(label))
result.textLabel.text = BOXSTRING(label);
result.detailTextLabel.text = BOXSTRING(buffer);
menu_entry_free(&entry);
if (label && !string_is_empty(label))
free(label);
return result;
}
@ -153,7 +158,7 @@ static void RunActionSheet(const char* title, const struct string_list* items,
- (UITableViewCell*)cellForTableView:(UITableView*)tableView
{
menu_entry_t entry;
char label[PATH_MAX_LENGTH];
char *label = NULL;
static NSString* const cell_id = @"boolean_setting";
UITableViewCell* result =
@ -169,9 +174,12 @@ static void RunActionSheet(const char* title, const struct string_list* items,
menu_entry_init(&entry);
menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true);
menu_entry_get_path(&entry, label, sizeof(label));
result.textLabel.text = BOXSTRING(label);
label = menu_entry_get_path(&entry);
if (label && !string_is_empty(label))
result.textLabel.text = BOXSTRING(label);
[(id)result.accessoryView removeTarget:nil
action:NULL
forControlEvents:UIControlEventValueChanged];
@ -180,6 +188,8 @@ static void RunActionSheet(const char* title, const struct string_list* items,
forControlEvents:UIControlEventValueChanged];
[(id)result.accessoryView setOn:(menu_entry_get_bool_value(self.i))];
menu_entry_free(&entry);
if (label && !string_is_empty(label))
free(label);
return result;
}
@ -215,16 +225,18 @@ static void RunActionSheet(const char* title, const struct string_list* items,
ofController:(UIViewController*)controller
{
menu_entry_t entry;
struct string_list* items;
char label[PATH_MAX_LENGTH];
struct string_list* items = NULL;
char *label = NULL;
RAMenuItemEnum __weak* weakSelf = self;
menu_entry_init(&entry);
menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true);
menu_entry_get_path(&entry, label, sizeof(label));
label = menu_entry_get_path(&entry);
items = menu_entry_enum_values(self.i);
RunActionSheet(label, items, self.parentTable,
if (label && !string_is_empty(label))
{
RunActionSheet(label, items, self.parentTable,
^(UIActionSheet* actionSheet, NSInteger buttonIndex)
{
if (buttonIndex == actionSheet.cancelButtonIndex)
@ -234,8 +246,11 @@ static void RunActionSheet(const char* title, const struct string_list* items,
(self.i, [[actionSheet buttonTitleAtIndex:buttonIndex] UTF8String]);
[weakSelf.parentTable reloadData];
});
}
string_list_free(items);
menu_entry_free(&entry);
if (label && !string_is_empty(label))
free(label);
}
@end
@ -250,13 +265,14 @@ static void RunActionSheet(const char* title, const struct string_list* items,
ofController:(UIViewController *)controller
{
menu_entry_t entry;
char label[PATH_MAX_LENGTH];
char *label = NULL;
menu_entry_init(&entry);
menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true);
menu_entry_get_path(&entry, label, sizeof(label));
label = menu_entry_get_path(&entry);
self.alert = [[UIAlertView alloc]
initWithTitle:BOXSTRING("RetroArch")
message:BOXSTRING(label)
delegate:self
@ -275,6 +291,8 @@ static void RunActionSheet(const char* title, const struct string_list* items,
userInfo:nil
repeats:YES];
menu_entry_free(&entry);
if (label && !string_is_empty(label))
free(label);
}
- (void)finishWithClickedButton:(bool)clicked
@ -426,14 +444,14 @@ replacementString:(NSString *)string
{
menu_entry_t entry;
char buffer[PATH_MAX_LENGTH];
char label[PATH_MAX_LENGTH];
char *label = NULL;
UIAlertView *alertView = NULL;
UITextField *field = NULL;
NSString *desc = NULL;
menu_entry_init(&entry);
menu_entry_get(&entry, 0, (unsigned)self.i, NULL, true);
menu_entry_get_path(&entry, label, sizeof(label));
label = menu_entry_get_path(&entry);
desc = BOXSTRING(label);
@ -458,6 +476,9 @@ replacementString:(NSString *)string
menu_entry_free(&entry);
if (label && !string_is_empty(label))
free(label);
[alertView show];
}