Exemple #1
0
int edit_pt(struct _LwVM *LwVM, bool pt_no_crc)
{
	char input[CLI_INPUT_BUFF_SZ];
	while(1)
	{
		printf("Command (? for help): ");
		
		fgets(&input[0], CLI_INPUT_BUFF_SZ, stdin);
		
		if (!strcmp(input, "?\n") || !strcmp(input, "help\n") || !strcmp(input, "h\n"))
		{
			edit_help();
		}
		else if (!strcmp(input, "print\n") || !strcmp(input, "p\n"))
		{
			print_pt(LwVM, pt_no_crc);
		}
		else if (!strcmp(input, "quit\n") || !strcmp(input, "q\n"))
		{
			break;
		}
		else if (!strcmp(input, "write\n") || !strcmp(input, "w\n"))
		{
			damage_warning();
			return SAVE_CHANGES;
		}
		else if (!strcmp(input, "add\n") || !strcmp(input, "a\n"))
		{
			if (*(&LwVM->numPartitions) < 12)
			{
				memset(&LwVM->partitions[*(&LwVM->numPartitions)], 0, sizeof(LwVMPartitionRecord));
				
				/*uint64_t new_guid[2];
				FILE *random_f = fopen("/dev/random", "r");
				while(fread(&new_guid, 1, 16, random_f) != 16);
				fclose(random_f);*/
				
				void *new_guid = gen_guid();
				
				memcpy(&LwVM->partitions[*(&LwVM->numPartitions)].guid[0], &new_guid[0], 16);
				*(&LwVM->numPartitions) = *(&LwVM->numPartitions) + 1;
				free(new_guid);
				printf("Done.\n");
			}
			else printf("Can't create more than 12 partitions.\n");
		}
		else if (!strcmp(input, "rm\n") || !strcmp(input, "r\n"))
		{
			if (*(&LwVM->numPartitions) == 0)
			{
				printf("Nothing to delete.\n\n");
				continue;
			}
			
			printf("Type the number of the partition you want to remove [1-%u]: ", *(&LwVM->numPartitions));
			
			fgets(&input[0], CLI_INPUT_BUFF_SZ, stdin);
			
			int part_num = atoi(input);
			
			if (pt_splice(LwVM, part_num) == E_NOPART)
			{
				printf("No such partition.\n");
			}
			else
			{
				printf("Done.\n");
			}
		}
		else if (!strcmp(input, "edit\n") || !strcmp(input, "e\n"))
		{
			printf("Type the number of the partition you want to edit [1-%u]: ", *(&LwVM->numPartitions));
			fgets(&input[0], CLI_INPUT_BUFF_SZ, stdin);
			
			int part_to_edit = atoi(input);
			part_to_edit--;
			if (part_to_edit < 12 && part_to_edit >= 0 && part_to_edit < *(&LwVM->numPartitions))
			{
				printf("What parameter do you want to edit? [begin/end/type/name] ");
				fgets(&input[0], CLI_INPUT_BUFF_SZ, stdin);
				
				if (!strcmp(input, "begin\n"))
				{
					printf("Begin [0-%llu(MB/GB)]: ", *(&LwVM->mediaSize));
					
					uint64_t new_begin = get_param_input();
					if (new_begin > *(&LwVM->mediaSize))
					{
						printf("Can't create a partition beyond the disk.\n");
					}
					else
					{
						*(&LwVM->partitions[part_to_edit].begin) = new_begin;
					}
				}
				else if (!strcmp(input, "end\n"))
				{
					printf("End [0-%llu(MB/GB)]: ", *(&LwVM->mediaSize));
					
					uint64_t new_end = get_param_input();
					if (new_end > *(&LwVM->mediaSize))
					{
						printf("Can't set partition begin beyond the disk.\n");
					}
					else
					{
						*(&LwVM->partitions[part_to_edit].end) = new_end;
					}
				}
				else if (!strcmp(input, "type\n"))
				{
					while(1)
					{
						printf("Enter partition type you want (? for help): ");
						fgets(&input[0], CLI_INPUT_BUFF_SZ, stdin);
						
						if (!strcmp(input, "?\n"))
						{
							available_part_types();
						}
						else if (!strcmp(input, "HFS+\n") || !strcmp(input, "hfs+\n"))
						{
							memcpy(&LwVM->partitions[part_to_edit].type, LwVMPartitionTypeHFSPlus, sizeof(*LwVMPartitionTypeHFSPlus));
							break;
						}
						else if (!strcmp(input, "LinuxData\n") || !strcmp(input, "linuxdata\n"))
						{
							memcpy(&LwVM->partitions[part_to_edit].type, LwVMPartitionTypeLinuxData, sizeof(*LwVMPartitionTypeLinuxData));
							break;
						}
						else if (!strcmp(input, "disabled\n") || !strcmp(input, "Disabled\n"))
						{
							memcpy(&LwVM->partitions[part_to_edit].type, LwVMPartitionTypeDisabled, sizeof(*LwVMPartitionTypeDisabled));
							break;
						}
						else
						{
							printf("Unknown type: %s\n", input);
							available_part_types();
						}
					}
				}
				else if (!strcmp(input, "name\n"))
				{
					printf("Type new name of the partition (max of 36 characters): ");
					fgets(&input[0], CLI_INPUT_BUFF_SZ, stdin);
					
					input[strlen(input) - 1] = 0; //Remove the \n byte.
					char *lwvm_name = str_to_lwvm_name(input);
					memcpy(&LwVM->partitions[part_to_edit].partitionName, lwvm_name, 0x48);
					
					free(lwvm_name);
				}
				else
				{
					printf("Invalid parameter name.\n");
				}
			}
			else
			{
				printf("Invalid number.\n");
			}
		}
		else if (strcmp(input, " \n") && strcmp(input, "\n"))
		{
			edit_help();
		}
		
		printf("\n");
	}
	
	return DISCARD_CHANGES;
}
Exemple #2
0
static cb_ret_t
edit_dialog_command_execute (WDialog * h, long command)
{
    Widget *wh = WIDGET (h);
    cb_ret_t ret = MSG_HANDLED;

    switch (command)
    {
    case CK_EditNew:
        edit_add_window (h, wh->y + 1, wh->x, wh->lines - 2, wh->cols, NULL, 0);
        break;
    case CK_EditFile:
        edit_load_cmd (h);
        break;
    case CK_EditSyntaxFile:
        edit_load_syntax_file (h);
        break;
    case CK_EditUserMenu:
        edit_load_menu_file (h);
        break;
    case CK_Close:
        /* if there are no opened files anymore, close MC editor */
        if (edit_widget_is_editor (CONST_WIDGET (h->current->data)) &&
            edit_close_cmd ((WEdit *) h->current->data) && find_editor (h) == NULL)
            dlg_stop (h);
        break;
    case CK_Help:
        edit_help ();
        /* edit->force |= REDRAW_COMPLETELY; */
        break;
    case CK_Menu:
        edit_menu_cmd (h);
        break;
    case CK_Quit:
    case CK_Cancel:
        /* don't close editor due to SIGINT, but stop move/resize window */
        {
            Widget *w = WIDGET (h->current->data);

            if (edit_widget_is_editor (w) && ((WEdit *) w)->drag_state != MCEDIT_DRAG_NONE)
                edit_restore_size ((WEdit *) w);
            else if (command == CK_Quit)
                dlg_stop (h);
        }
        break;
    case CK_About:
        edit_about ();
        break;
    case CK_SyntaxOnOff:
        edit_syntax_onoff_cmd (h);
        break;
    case CK_ShowTabTws:
        edit_show_tabs_tws_cmd (h);
        break;
    case CK_ShowMargin:
        edit_show_margin_cmd (h);
        break;
    case CK_ShowNumbers:
        edit_show_numbers_cmd (h);
        break;
    case CK_Refresh:
        edit_refresh_cmd ();
        break;
    case CK_Shell:
        view_other_cmd ();
        break;
    case CK_LearnKeys:
        learn_keys ();
        break;
    case CK_WindowMove:
    case CK_WindowResize:
        if (edit_widget_is_editor (CONST_WIDGET (h->current->data)))
            edit_handle_move_resize ((WEdit *) h->current->data, command);
        break;
    case CK_WindowList:
        edit_window_list (h);
        break;
    case CK_WindowNext:
        dlg_select_next_widget (h);
        break;
    case CK_WindowPrev:
        dlg_select_prev_widget (h);
        break;
    case CK_Options:
        edit_options_dialog (h);
        break;
    case CK_OptionsSaveMode:
        edit_save_mode_cmd ();
        break;
    case CK_SaveSetup:
        save_setup_cmd ();
        break;
    default:
        ret = MSG_NOT_HANDLED;
        break;
    }

    return ret;
}
Exemple #3
0
static cb_ret_t
edit_dialog_command_execute (Dlg_head * h, unsigned long command)
{
    gboolean ret = MSG_HANDLED;

    switch (command)
    {
    case CK_EditNew:
        edit_add_window (h, h->y + 1, h->x, h->lines - 2, h->cols, NULL, 0);
        break;
    case CK_EditFile:
        edit_load_cmd (h);
        break;
    case CK_EditSyntaxFile:
        edit_load_syntax_file (h);
        break;
    case CK_EditUserMenu:
        edit_load_menu_file (h);
        break;
    case CK_Close:
        /* if there are no opened files anymore, close MC editor */
        if (edit_widget_is_editor ((Widget *) h->current->data) &&
            edit_close_cmd ((WEdit *) h->current->data) && find_editor (h) == NULL)
            dlg_stop (h);
        break;
    case CK_Help:
        edit_help ();
        /* edit->force |= REDRAW_COMPLETELY; */
        break;
    case CK_Menu:
        edit_menu_cmd (h);
        break;
    case CK_Quit:
    case CK_Cancel:
        {
            Widget *w = (Widget *) h->current->data;

            if (!edit_widget_is_editor (w) || ((WEdit *) w)->drag_state == MCEDIT_DRAG_NORMAL)
                dlg_stop (h);
            else
                edit_restore_size ((WEdit *) w);
        }
        break;
    case CK_About:
        edit_about ();
        break;
    case CK_SyntaxOnOff:
        edit_syntax_onoff_cmd (h);
        break;
    case CK_ShowTabTws:
        edit_show_tabs_tws_cmd (h);
        break;
    case CK_ShowMargin:
        edit_show_margin_cmd (h);
        break;
    case CK_ShowNumbers:
        edit_show_numbers_cmd (h);
        break;
    case CK_Refresh:
        edit_refresh_cmd ();
        break;
    case CK_Shell:
        view_other_cmd ();
        break;
    case CK_LearnKeys:
        learn_keys ();
        break;
    case CK_WindowMove:
    case CK_WindowResize:
        if (edit_widget_is_editor ((Widget *) h->current->data))
            edit_handle_move_resize ((WEdit *) h->current->data, command);
        break;
    case CK_WindowList:
        edit_window_list (h);
        break;
    case CK_WindowNext:
        dlg_one_down (h);
        dlg_set_top_widget (h->current->data);
        break;
    case CK_WindowPrev:
        dlg_one_up (h);
        dlg_set_top_widget (h->current->data);
        break;
    case CK_Options:
        edit_options_dialog (h);
        break;
    case CK_OptionsSaveMode:
        edit_save_mode_cmd ();
        break;
    case CK_SaveSetup:
        save_setup_cmd ();
        break;
    default:
        ret = MSG_NOT_HANDLED;
        break;
    }

    return ret;
}