Example #1
0
static void initialize_launchers( HWND hwnd )
{
    HRESULT hr, init;
    TEXTMETRICW tm;
    int icon_size;

    if (!(get_icon_text_metrics( hwnd, &tm ))) return;

    icon_cx = GetSystemMetrics( SM_CXICON );
    icon_cy = GetSystemMetrics( SM_CYICON );
    icon_size = max( icon_cx, icon_cy );
    title_cy = tm.tmHeight * 2;
    title_cx = max( tm.tmAveCharWidth * TITLE_CHARS, icon_size + PADDING_SIZE + title_cy );
    launcher_size = BORDER_SIZE + title_cx + BORDER_SIZE;
    icon_offset_cx = (launcher_size - icon_cx) / 2;
    icon_offset_cy = BORDER_SIZE + (icon_size - icon_cy) / 2;
    title_offset_cx = BORDER_SIZE;
    title_offset_cy = BORDER_SIZE + icon_size + PADDING_SIZE;
    desktop_width = GetSystemMetrics( SM_CXSCREEN );
    launchers_per_row = desktop_width / launcher_size;

    hr = SHGetKnownFolderPath( &FOLDERID_Desktop, KF_FLAG_CREATE, NULL, &desktop_folder );
    if (FAILED( hr ))
    {
        WINE_ERR("Could not get user desktop folder\n");
        return;
    }
    hr = SHGetKnownFolderPath( &FOLDERID_PublicDesktop, KF_FLAG_CREATE, NULL, &desktop_folder_public );
    if (FAILED( hr ))
    {
        WINE_ERR("Could not get public desktop folder\n");
        CoTaskMemFree( desktop_folder );
        return;
    }
    if ((launchers = HeapAlloc( GetProcessHeap(), 0, 2 * sizeof(launchers[0]) )))
    {
        nb_allocated = 2;

        init = CoInitialize( NULL );
        add_folder( desktop_folder );
        add_folder( desktop_folder_public );
        if (SUCCEEDED( init )) CoUninitialize();

        CreateThread( NULL, 0, watch_desktop_folders, hwnd, 0, NULL );
    }
}
Example #2
0
int main(int argc, char *argv[]){
	char *command;
	int i, num;
	char **list;
	int layer, right;
	char *mount_path, *share;
	int result;

	if((command = rindex(argv[0], '/')) != NULL)
		++command;
	else
		command = argv[0];

	if(!strcmp(command, "get_account_list")){
		if(get_account_list(&num, &list) <= 0)
			usb_dbg("Can't get account list.\n");
		else{
			for(i = 0; i < num; ++i)
				usb_dbg("%dth account: %s.\n", i+1, list[i]);

			free_2_dimension_list(&num, &list);
		}
	}
	else if(!strcmp(command, "get_folder_list")){
		if(argc != 2)
			usb_dbg("Usage: get_folder_list mount_path\n");
		else if(get_folder_list(argv[1], &num, &list) < 0)
			usb_dbg("Can't get folder list.\n");
		else{
			for(i = 0; i < num; ++i)
				usb_dbg("%dth folder: %s.\n", i+1, list[i]);

			free_2_dimension_list(&num, &list);
		}
	}
	else if(!strcmp(command, "get_all_folder")){
		if(argc != 2)
			usb_dbg("Usage: get_all_folder mount_path\n");
		else if(get_all_folder(argv[1], &num, &list) < 0)
			usb_dbg("Can't get all folder.\n");
		else{
			for(i = 0; i < num; ++i)
				usb_dbg("%dth folder: %s.\n", i+1, list[i]);

			free_2_dimension_list(&num, &list);
		}
	}
	else if(!strcmp(command, "get_var_file_name")){
		char *file_name;

		if(argc != 3)
			usb_dbg("Usage: get_var_file_name account mount_path\n");
		else if(get_var_file_name(argv[1], argv[2], &file_name))
			usb_dbg("Can't get the var file name with %s in %s.\n", argv[1], argv[2]);
		else{
			usb_dbg("done: %s.\n", file_name);
			free(file_name);
		}
	}
	else if(!strcmp(command, "initial_folder_list")){
		if(argc != 2)
			usb_dbg("Usage: initial_folder_list mount_path\n");
		else if(initial_folder_list(argv[1]) < 0)
			usb_dbg("Can't initial folder list in %s.\n", argv[1]);
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "initial_var_file")){
		char *target_acc = NULL;

		if(argc != 3){
			usb_dbg("Usage: initial_var_file account mount_path\n");
			return -1;
		}

		if(strcmp(argv[1], "NULL"))
			target_acc = argv[1];

		if(initial_var_file(target_acc, argv[2]) < 0){
			if(target_acc == NULL)
				usb_dbg("Can't initial share's var file in %s.\n", argv[2]);
			else
				usb_dbg("Can't initial %s's var file in %s.\n", target_acc, argv[2]);
		}
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "initial_all_var_file")){
		if(argc != 2)
			usb_dbg("Usage: initial_all_var_file mount_path\n");
		else if(initial_all_var_file(argv[1]) < 0)
			usb_dbg("Can't initial all var file in %s.\n", argv[1]);
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "test_of_var_files")){
		if(argc != 2)
			usb_dbg("Usage: test_of_var_files mount_path\n");
		else if(test_of_var_files(argv[1]) < 0)
			usb_dbg("Can't test_of_var_files in %s.\n", argv[1]);
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "create_if_no_var_files")){
		if(argc != 2)
			usb_dbg("Usage: create_if_no_var_files mount_path\n");
		else if(create_if_no_var_files(argv[1]) < 0)
			usb_dbg("Can't create var files in %s.\n", argv[1]);
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "modify_if_exist_new_folder")){
		if(argc != 3)
			usb_dbg("Usage: modify_if_exist_new_folder account mount_path\n");
		else if(modify_if_exist_new_folder(argv[1], argv[2]) < 0)
			usb_dbg("Can't fix %s's var files in %s.\n", argv[1], argv[2]);
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "get_permission")){
		if(argc != 5)
			usb_dbg("Usage: get_permission account mount_path folder [cifs|ftp|dms]\n");
		else if((right = get_permission(argv[1], argv[2], argv[3], argv[4])) < 0)
			usb_dbg("%s can't get %s's %s permission in %s.\n", argv[1], argv[3], argv[4], argv[2]);
		else
			usb_dbg("done: %d.\n", right);
	}
	else if(!strcmp(command, "set_permission")){
		if(argc != 6)
			usb_dbg("Usage: set_permission account mount_path folder [cifs|ftp|dms] [0~3]\n");
		else if(set_permission(argv[1], argv[2], argv[3], argv[4], atoi(argv[5])) < 0)
			usb_dbg("%s can't set %s's %s permission to be %s in %s.\n", argv[1], argv[3], argv[4], argv[5], argv[2]);
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "add_account")){
		if(argc != 3)
			usb_dbg("Usage: add_account account password\n");
		else if(add_account(argv[1], argv[2]) < 0)
			usb_dbg("Can't add account(%s:%s).\n", argv[1], argv[2]);
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "del_account")){
		if(argc != 2)
			usb_dbg("Usage: del_account account\n");
		else if(del_account(argv[1]) < 0)
			usb_dbg("Can't del account(%s).\n", argv[1]);
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "mod_account")){
		if(argc != 4)
			usb_dbg("Usage: mod_account account new_account new_password\n");
		else if(mod_account(argv[1], argv[2], argv[3]) < 0)
			usb_dbg("Can't mod account(%s) to (%s:%s).\n", argv[1], argv[2], argv[3]);
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "test_if_exist_account")){
		if(argc != 2)
			usb_dbg("Usage: test_if_exist_account account\n");
		else if(test_if_exist_account(argv[1]) < 0)
			usb_dbg("Can't test if %s is existed.\n", argv[1]);
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "add_folder")){
		if(argc != 4){
			usb_dbg("Usage: add_folder account mount_path folder\n");
			return 0;
		}
		
		if(!strcmp(argv[1], "NULL"))
			result = add_folder(NULL, argv[2], argv[3]);
		else
			result = add_folder(argv[1], argv[2], argv[3]);
		if(result < 0)
			usb_dbg("Can't add folder(%s) in %s.\n", argv[3], argv[2]);
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "del_folder")){
		if(argc != 3)
			usb_dbg("Usage: del_folder mount_path folder\n");
		else if(del_folder(argv[1], argv[2]) < 0)
			usb_dbg("Can't del folder(%s) in %s.\n", argv[2], argv[1]);
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "mod_folder")){
		if(argc != 4)
			usb_dbg("Usage: mod_folder mount_path folder new_folder\n");
		else if(mod_folder(argv[1], argv[2], argv[3]) < 0)
			usb_dbg("Can't mod folder(%s) to (%s) in %s.\n", argv[2], argv[3], argv[1]);
		else
			usb_dbg("done.\n");
	}
	else if(!strcmp(command, "test_if_exist_share")){
		if(argc != 3)
			usb_dbg("Usage: test_if_exist_share mount_path folder\n");
		else if(test_if_exist_share(argv[1], argv[2]))
			usb_dbg("%s is existed in %s.\n", argv[2], argv[1]);
		else
			usb_dbg("%s is NOT existed in %s.\n", argv[2], argv[1]);
	}
	else if(!strcmp(command, "how_many_layer")){
		if(argc != 2)
			usb_dbg("Usage: how_many_layer path\n");
		else if((layer = how_many_layer(argv[1], &mount_path, &share)) < 0)
			usb_dbg("Can't count the layer with %s.\n", argv[1]);
		else
			usb_dbg("done: %d layers, share=%s, mount_path=%s.\n", layer, share, mount_path);
	}
	else
		usb_dbg("test_share(ver. %d): Need to link the command name from test_share first.\n", VERSION);

	return 0;
}
Example #3
0
int mod_folder(const char *const mount_path, const char *const folder, const char *const new_folder) {
	int result, i, len;
	int acc_num = 0;
	char **account_list = NULL;
	char var_file[256];
	char *target, *new_target, *var_info;
	FILE *fp;
	char *follow_info, backup;
	char *full_path, *new_full_path;
	
	if (mount_path == NULL || strlen(mount_path) <= 0) {
		return -1;
	}
	if (folder == NULL || strlen(folder) <= 0) {
		return -1;
	}
	if (new_folder == NULL || strlen(new_folder) <= 0) {
		return -1;
	}
	
	// 1. test if modifying the folder
	len = strlen(mount_path)+strlen("/")+strlen(folder);
	full_path = (char *)malloc(sizeof(char)*(len+1));
	if (full_path == NULL) {
		return -1;
	}
	sprintf(full_path, "%s/%s", mount_path, folder);
	full_path[len] = 0;
	
	len = strlen(mount_path)+strlen("/")+strlen(new_folder);
	new_full_path = (char *)malloc(sizeof(char)*(len+1));
	if (new_full_path == NULL) {
		return -1;
	}
	sprintf(new_full_path, "%s/%s", mount_path, new_folder);
	new_full_path[len] = 0;
	
	result = test_if_exist_folder_in_mount_path(mount_path, folder);
	if (result == 0) {
		result = test_if_dir(full_path);
		
		if (result != 1) {
			free(full_path);
			free(new_full_path);
			
			return -1;
		}
		
		// the folder is existed but not in .__folder_list.txt
		add_folder(mount_path, folder);
	}
	
	//  modify the folder
	result = rename(full_path, new_full_path);
	free(full_path);
	free(new_full_path);
	if (result != 0) {
		return -1;
	}
	
	len = strlen("*")+strlen(folder)+strlen("=");
	target = (char *)malloc(sizeof(char)*(len+1));
	if (target == NULL) {
		return -1;
	}
	sprintf(target, "*%s=", folder);
	target[len] = 0;
	
	len = strlen("*")+strlen(new_folder)+strlen("=");
	new_target = (char *)malloc(sizeof(char)*(len+1));
	if (new_target == NULL) {
		free(target);
		return -1;
	}
	sprintf(new_target, "*%s=", new_folder);
	new_target[len] = 0;
	
	// 3. add folder's right to every var file
	get_account_list(&acc_num, &account_list);
	
	for (i = 0; i < acc_num; ++i) {
		// check if the created target is exist in the var file
		snprintf(var_file, sizeof(var_file), "%s/.__%s_var.txt", mount_path, account_list[i]);
		var_info = read_whole_file(var_file);
		if (var_info == NULL) {
			continue;
		}
		
		if ((follow_info = strstr(var_info, target)) == NULL) {
			free(var_info);
			continue;
		}
		
		// 7. modify the folder's info in the var file
		fp = fopen(var_file, "w");
		if (fp) {
			// write the info before target
			backup = *follow_info;
			*follow_info = 0;
			fprintf(fp, "%s", var_info);
			*follow_info = backup;
			
			// write the info before new_target
			fprintf(fp, "%s", new_target);
			
			// write the info after target
			follow_info += strlen(target);
			fprintf(fp, "%s", follow_info);
			
			fclose(fp);
		}
		
		free(var_info);
	}
	
	free_2_dimension_list(&acc_num, &account_list);
	
	// get the var_file for anonymous ftp
	snprintf(var_file, sizeof(var_file), "%s/.__%s_var.txt", mount_path, FTP_ANONYMOUS_USER);
	var_info = read_whole_file(var_file);
	if (var_info) {
		if ((follow_info = strstr(var_info, target))) {
			fp = fopen(var_file, "w");
			if (fp) {
				// write the info before target
				backup = *follow_info;
				*follow_info = 0;
				fprintf(fp, "%s", var_info);
				*follow_info = backup;
				
				// write the info before new_target
				fprintf(fp, "%s", new_target);
				
				// write the info after target
				follow_info += strlen(target);
				fprintf(fp, "%s", follow_info);
				
				fclose(fp);
			}
		}
		
		free(var_info);
	}
	
	free(target);
	free(new_target);
	
	// 9. modify the folder's info in the folder list
	initial_folder_list_in_mount_path(mount_path);
	
	return 0;
}