gpt4 book ai didi

C Web 浏览器下载文件

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:28:01 24 4
gpt4 key购买 nike

WebkitGTK+ API Reference

我想做的是在 Linux 上运行我的 HTML5 应用程序,这样我和我的用户仍然可以在不依赖互联网连接的情况下使用我的应用程序。

我的问题是当我去下载一个 zip 文件时。下载不会执行,因为没有足够的 url 来保存文件(如桌面)。因此它不下载。

因此,我的问题依赖于当通过 JSZip 动态执行文件时,我应该如何获得足够的 url 来下载该文件? . (它在 Chrome 中工作正常,只是在我的应用程序中不工作)。终端说...

source.c:35:3: warning: ‘return’ with a value, in function returning void [enabled by default] return TRUE; ^

这是我的代码:

/*
Save this file as main.c and compile it using this command
(those are backticks, not single quotes):
gcc -Wall -g -o source source.c `pkg-config --cflags --libs gtk+-2.0 webkit-1.0` -export-dynamic

Then execute it using:
./source

If you can't compile chances are you don't have gcc installed.
Install gcc/c with the following terminal command. (This command is for Debian based Linux distros)
sudo apt-get install libgtk2.0-dev libgtk2.0-doc libglib2.0-doc

WebKit requires libraries to successfully aquire, configure, and compile. You can get libraries by issuing the following command in your terminal:
sudo apt-get install subversion gtk-doc-tools autoconf automake libtool libgtk2.0-dev libpango1.0-dev libicu-dev libxslt-dev libsoup2.4-dev libsqlite3-dev gperf bison flex libjpeg62-dev libpng12-dev libxt-dev autotools-dev libgstreamer-plugins-base0.10-dev libenchant-dev libgail-dev

WebkitGTK+ API Reference: http://webkitgtk.org/reference/webkitgtk/stable/webkitgtk-webkitdownload.html

Ubuntu Webkit information - https://help.ubuntu.com/community/WebKit
sudo apt-get install libwebkitgtk-dev python-webkit-dev python-webkit

Required dependencies for this build: (If you installed all the above this is not needed)
sudo apt-get install libgtk2.0-dev libgtk2.0-doc libglib2.0-doc subversion gtk-doc-tools autoconf automake libtool libgtk2.0-dev libpango1.0-dev libicu-dev libxslt-dev libsoup2.4-dev libsqlite3-dev gperf bison flex libjpeg62-dev libpng12-dev libxt-dev autotools-dev libgstreamer-plugins-base0.10-dev libenchant-dev libgail-dev libwebkitgtk-dev
*/

#include <gtk/gtk.h>
#include <webkit/webkit.h>

static void destroy_cb(GtkWidget* widget, gpointer data) {
gtk_main_quit();
}

static void download_requested_cb(WebKitWebView *web_view, WebKitDownload *download) {
const gchar* dest = g_strdup_printf("%s", "file:///home/michael/Downloads/test.zip");
//set the destination uri (eg, send the file to a downloads folder)
webkit_download_set_destination_uri(download, dest);
webkit_download_start();

return TRUE;
}

int main(int argc, char* argv[]) {
GtkWidget* window;
WebKitWebView* web_view;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_name (window, "AppName");
gtk_window_set_default_size(GTK_WINDOW(window), 600, 600);
//gtk_window_set_icon_from_file(window, "app/logo.png", NULL);
g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);

web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());

/* Register a callback that gets invoked each time a download is requested */
g_object_connect(web_view, "download-requested", G_CALLBACK(download_requested_cb), NULL);

char uri[PATH_MAX];
char cwd[PATH_MAX];

getcwd(cwd, sizeof(cwd));

if (argc > 1)
snprintf(uri, sizeof(uri), "%s", argv[1]);
else
snprintf(uri, sizeof(uri), "file://%s/app/index.html", cwd);

webkit_web_view_open (web_view, uri);

gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(web_view));
gtk_widget_grab_focus(GTK_WIDGET(web_view));
gtk_widget_show_all(window);
gtk_main();
return 0;
}

最佳答案

1) 你的基本前提是合理的:

file:///home/michael/Downloads/test.zip//此语法应允许您“上传”硬盘上的本地文件

2) 这是编译警告(不是错误)。理论上,您可以忽略它:

source.c:35:3: warning: ‘return’ with a value, in function returning void [enabled by default] return TRUE; ^

3) 这是问题所在:

static void download_requested_cb(WebKitWebView *web_view, ... 
...
return TRUE; // Delete this line. You can't return anything from a "void" function!
}

关于C Web 浏览器下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31488767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com