以上就是给各位分享织梦CMS新闻模型整合download功能——可判断点数,会员组等download权限,其中也会对织梦cms怎么样进行解释,同时本文还将给你拓展android–在webview已经获
以上就是给各位分享织梦CMS新闻模型整合download功能——可判断点数,会员组等download权限,其中也会对织梦cms怎么样进行解释,同时本文还将给你拓展android – 在webview已经获取文件后调用setDownloadListener onDownloadStart吗?、android – 未知的URL内容:// downloads / my_downloads、c# – DownloadFile vs DownloadFileAsync、com.intellij.util.download.DownloadableFileDescription的实例源码等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- 织梦CMS新闻模型整合download功能——可判断点数,会员组等download权限(织梦cms怎么样)
- android – 在webview已经获取文件后调用setDownloadListener onDownloadStart吗?
- android – 未知的URL内容:// downloads / my_downloads
- c# – DownloadFile vs DownloadFileAsync
- com.intellij.util.download.DownloadableFileDescription的实例源码
织梦CMS新闻模型整合download功能——可判断点数,会员组等download权限(织梦cms怎么样)
本教程实现DEDECMS功能:新闻模型整合download功能,可判断点数,会员组等download权限,前台可判断是否有附件download,有则显示,没有则不显示。适用类型:有些新闻有download地址,有些新闻没有download地址的网站。想附件收费的网站等等……具体就不啰嗦了。用得上您就拿走。DEDECMS新闻模型整合download功能,可判断点数,会员组等download权限
后台效果图
本教程为网站管理员似水星辰原创,转载注明出处。
注:本教程中的金币和会员组设置只针对download连接有效。不对新闻内容生效,和新闻本身的阅读权限和消费金币并不冲突,是分开设置的。新闻中所有sql语句中涉及表名的,请把表前缀换成您自己的表前缀。如:js_addonarticle 换成 您的表前缀_addonarticle。
一、首先规划要加入的字段
download链接:softlinks
消费金币:needmoney
会员组权限:daccess
这些字段要加入到新闻附加表中,前缀_addonarticle,也可以根据自己情况加入需要的表中,自己修改就行了。
进入后台系统-SQL命令行工具,执行:
ALTER TABLE `js_addonarticle` ADD `softlinks` TEXT NOT NULL ,
ADD `needmoney` SMALLINT( 5 ) NOT NULL ,
ADD `daccess` SMALLINT( 5 ) NOT NULL
也可以在phpmyadmin中自行添加。
然后在后台打开核心-频道模型-内容模型管理-普通新闻-修改-字段管理,在模型字段配置(文本模式) 里添加
<field:softlinks itemname="软件地址" type="softlinks" isnull="true" default="" rename="" />
<field:daccess islist="1" itemname="download级别" type="int" isnull="true" default="0" rename="" function="" notsend="1" />
<field:needmoney islist="1" itemname="需要金币" type="int" isnull="true" default="0" rename="" function="" notsend="1" />
如果不添加则会出现无链接信息错误!请务必添加。
二、数据库字段添加完毕就要修改新闻模型的4个文件了。分别是dede管理目录下的article_add.php,article_edit.php和管理源码article_add.htm,article_edit.htm,打开这4个文件依次修改。
1、修改article_add.htm,在头部的
<script></script>
中加入以下,在</script>
之前加入就行
var startNum = 0;
function MakeUpload()
{
var upfield = document.getElementById("uploadfield");
var endNum = parseInt(document.form1.picnum.value) + startNum-1;
if(endNum > 30) endNum = 30;
for(startNum; startNum<=endNum; startNum++){
upfield.innerHTML += "<div>软件地址"+startNum+":<input type="text" name="softurl"+startNum+""value="" /> 服务器名称:<input type="text" name="servermsg"+startNum+""/></div>\r\n";
}
}
function ShowHideAddr()
{
document.getElementById('morelink').style.display = (document.getElementById('morelink').style.display=='block' ? 'none' : 'block');
document.getElementById('morelink').style.height = '100%';
document.getElementById('btsh3').value = (document.getElementById('morelink').style.display=='block' ? '隐藏地址' : '显示地址');
}
这个是可以增加download地址个数的JS代码。
2、找到<tr><td colspan="2"><?php PrintAutoFieldsAdd($cInfos['fieldset'],'autofield'); ?></td></tr>再其后边加入<tr><td height="24" bgcolor="#F9FCEF""><strong> download限制:</strong></td></tr><tr><td height="24"><table width="800" border="0" cellpadding="0" cellspacing="0"><tr><td width="90" height="30"> 需会员权限:</td><td width="179" align="left"><select name="daccess" id="daccess"> <?php
$dsql->SetQuery("Select * from `js_arcrank` where rank>=0 ");
$dsql->Execute();
while($row = $dsql->GetArray())
{
if($row['rank']==0) $row['membername'] = "不限会员";
if($row['rank'] == $softconfig['dfrank']) echo " <option value='{$row['rank']}' selected>{$row['membername']}</option>\r\n";
else echo " <option value='{$row['rank']}'>{$row['membername']}</option>\r\n";
}
?> </select> </td><td width="120" align="center">需消费金币:</td><td width="411"><input name="needmoney" type="text" id="needmoney" value="<?php echo $softconfig['dfywboy']; ?>" size="8" />个</td></tr><tr><td height="26" colspan="4"> <span>(如果设定了download限制,[<a href=http://www.dede58.com/a/dedejq/"soft_config.php" target="_blank"><u>软件频道设置</u></a>]中“附件download方式:”必须选择“链接到跳转页面”) </span></td></tr></table></td></tr><tr><td height="24" bgcolor="#F9FCEF"><strong> 本地软件选择:</strong></td></tr><tr><td height="24"><table width="800" border="0" cellspacing="0" cellpadding="0"><tr><td width="90" height="30"> 本地地址:</td><td><input name="softurl1" type="text" id="softurl1" size="35" /> <input name="sel1" type="button" id="sel1" value="选取" onclick="SelectSoft('form1.softurl1')" /> 服务器名称: <input name="servermsg1" type="text" id="servermsg1" value="本地download"/> </td></tr></table></td></tr><?php
if($softconfig['moresitedo'] == 0 && trim($softconfig['sites']) != '')
{
?><tr><td height="24" bgcolor="#F9FCEF"><b> 预设的镜像服务器:</b></td></tr><tr><td>(服务器地址 + 软件地址 = 软件真实地址 [<a href=http://www.dede58.com/a/dedejq/"soft_config.php" target="_blank"><u>软件频道设置</u></a>])
<?php
$sites = explode("\n", $softconfig['sites']);
$startNum = 2;
foreach($sites as $site)
{
$site = trim($site);
if(empty($site)) continue;
list($siteurl, $sitename) = explode('|', $site);
$siteurl = trim($siteurl);
$sitename = trim($sitename);
?>
<?php echo $sitename; ?>: <input type="hidden" name="forconfig<?php echo $startNum; ?>" value="1" /> <input type="text" name="softurlfirst<?php echo $startNum; ?>"value="<?php echo $siteurl; ?>" /> + <input type="text" name="softurl<?php echo $startNum; ?>"value="" /> <input type="text" name="servermsg<?php echo $startNum; ?>"value="<?php echo $sitename; ?>" /> <input type="checkbox" name="need<?php echo $startNum; ?>"value="1" checked="checked" />启用
<?php
$startNum++;
}//foreach
echo "
<script language="javascript">startNum = $startNum;</script>
\r\n";
?></td></tr><?php
}//需要预设镜像
?><tr><td height="24" bgcolor="#F9FCEF"><b> 手动指定地址:</b></td></tr><tr><td height="24"><table width="800" border="0" cellspacing="0" cellpadding="0"><tr><td width="90">其它地址:</td><td><input name="picnum" type="text" id="picnum" size="8" value="5" /> <input name="kkkup" type="button" id="kkkup2" value="增加地址" onclick="MakeUpload();" /> <input type="button" name="Submit3" id="btsh3" value="隐藏地址" onclick="ShowHideAddr();" /> (*多为30个链接)</td></tr></table><div id="morelink"><div id="uploadfield"></div></div></td></tr>到这里article_add.htm文件就修改完了。
3、打开article_edit.htm文件,在头部的
<script></script>
中加入以下代码,在</script>
之前加入就行
var startNum = <?php echo $newRowStart?>;
function MakeUpload()
{
var upfield = document.getElementById('uploadfield');
var endNum = parseInt(document.form1.picnum.value) + startNum;
if(endNum > 30) endNum = 30;
for(startNum; startNum < endNum; startNum++)
{
upfield.innerHTML += "<div>软件地址"+startNum+":<input type="text" name="softurl"+startNum+""value="" /> 服务器名称:<input type="text" name="servermsg"+startNum+""/></div>\r\n";
}
}
function ShowHideAddr()
{
document.getElementById('morelink').style.display = (document.getElementById('morelink').style.display=='block' ? 'none' : 'block');
document.getElementById('btsh3').value = (document.getElementById('morelink').style.display=='block' ? '隐藏地址' : '显示地址');
}
4、找到<tr><td colspan="2"><?php
PrintAutoFieldsEdit($cInfos['fieldset'],$addRow,'autofield');
?></td></tr>在其下边加入以下代码:<tr><td height="24"><table width="800" border="0" cellpadding="0" cellspacing="0"><tr><td width="90" height="30"> 需会员权限:</td><td width="179" align="center"><select name="daccess" id="daccess"> <?php
$dsql->SetQuery("Select * from `js_arcrank` where rank>=0 ");
$dsql->Execute();
while($row = $dsql->GetArray())
{
if($row['rank']==0) $row['membername'] = "不限会员";
if($row['rank'] == $daccess) echo " <option value='{$row['rank']}' selected>{$row['membername']}</option>\r\n";
else echo " <option value='{$row['rank']}'>{$row['membername']}</option>\r\n";
}
?> </select> </td><td width="120" align="center">需消费金币:</td><td width="411"><input name="needmoney" type="text" id="needmoney" value="<?php echo $needmoney; ?>" size="8" />个</td></tr><tr><td height="26" colspan="4"> <span>(如果设定了download限制,<a href=http://www.dede58.com/a/dedejq/"soft_config.php" target="_blank"><u>软件频道设置</u></a>中“附件download方式:”必须选择“链接到跳转页面”) </span></td></tr></table></td></tr><tr><td height="24" colspan="4" bgcolor="#F9FCEF"><strong> 软件链接列表:</strong></td></tr><tr><td height="24" colspan="4"><table width="800" border="0" cellspacing="0" cellpadding="0"><tr><td width="72"> 其它地址:</td><td><input name="picnum" type="text" id="picnum" size="8" value="5" /> <input name="kkkup" type="button" id="kkkup2" value="增加数量" onclick="MakeUpload();" /> <input type="button" name="Submit3" id="btsh3" value="隐藏地址" onclick="ShowHideAddr();" /> (*多为30个链接)</td></tr></table></td></tr><tr><td height="24" colspan="4"><?php
echo $nForm;
?><div id="morelink"><div id="uploadfield"></div></div></td></tr>article_edit.html修改完毕,接下来开始修改article_add.php,要认真看哦!
5、打开article_add.php,找到
//保存到附加表
$cts = $dsql->GetOne("SELECT addtable FROM `js_channeltype` WHERE id='$channelid' ");
在其上边加入
//软件链接列表
$urls = '';
//本地链接处理
$softurl1 = stripslashes($softurl1);
$nsoftsize = '';
if($softurl1 != '')
{
$urls .= "{dede:link islocal='1' text='{$servermsg1}'} $softurl1 {/dede:link}\r\n";
}
//其它链接处理
for($i=2; $i<=30; $i++)
{
if(!(${'softurl'.$i}))
{
$forconfig = (${'forconfig'.$i}) ? FALSE : TRUE;
if($forconfig)
{
if(empty(${'need'.$i})) continue;
$serverUrl = stripslashes(${'softurlfirst'.$i});
$serverUrl = preg_replace("#\/$#", "", $serverUrl);
$softurl = stripslashes(${'softurl'.$i});
if( cn_substr($softurl, 1) != '/' ) $softurl = '/'.$softurl;
$softurl = $serverUrl.$softurl;
}
else
{
$softurl = stripslashes(${'softurl'.$i});
}
$servermsg = str_replace("'", "", stripslashes(${'servermsg'.$i}));
if($servermsg=='') $servermsg = 'download地址'.$i;
if($softurl != '')
{
$urls .= "{dede:link text='$servermsg'} $softurl {/dede:link}\r\n";
}
}
}
$urls = addslashes($urls);
这段大概在203行左右,主要作用是处理download地址。然后再找到
$query = "INSERT INTO `{$addtable}`(aid,typeid,redirecturl,templet,userip,body{$inadd_f}) Values('$arcID','$typeid','$redirecturl','$templet','$useip','$body'{$inadd_v})";
替换为
$query = "INSERT INTO `{$addtable}`(aid,typeid,redirecturl,templet,userip,body,softlinks,needmoney,daccess{$inadd_f}) Values('$arcID','$typeid','$redirecturl','$templet','$useip','$body','$urls','$needmoney','$daccess'{$inadd_v})";
article_add.php修改完毕,添加一下新闻,把download地址,金币,会员组都写进去,看看数据库是不是有这条记录了^ ^。
6、打开article_edit.php,找到
$channelid = $arcRow['channel'];
在其上边加入
$newRowStart = 1;
$nForm = '';
$daccess = $addRow['daccess'];
$needmoney = $addRow['needmoney'];
if($addRow['softlinks'] != '')
{
$dtp = new DedeTagParse();
$dtp->LoadSource($addRow['softlinks']);
if(is_array($dtp->CTags))
{
foreach($dtp->CTags as $ctag)
{
if($ctag->GetName()=='link')
{
$islocal = $ctag->GetAtt('islocal');
if($islocal != 1) $needmsg = "<input type="checkbox" name="del{$newRowStart}" value="1" />删除";
else $needmsg = '<input name="sel1" type="button" id="sel1" value="选取" onclick="SelectSoft(\'form1.softurl'.$newRowStart.'\')" />';
$nForm .= "<div>软件地址{$newRowStart}:<input type="text" name="softurl{$newRowStart}"value="".trim($ctag->GetInnerText())."" /> 服务器名称:<input type="text" name="servermsg{$newRowStart}" value="".$ctag->GetAtt("text").""/> <input type="hidden" name="islocal{$newRowStart}" value="{$islocal}" /> $needmsg</div>\r\n";
$newRowStart++;
}
}
}
$dtp->Clear();
}
找到
$cts = $dsql->GetOne("SELECT addtable FROM `js_channeltype` WHERE id='$channelid' ");
在其上边加入以下代码:
//软件链接列表
$urls = '';
for($i=1; $i<=30; $i++)
{
if(!empty(${'softurl'.$i}))
{
$islocal = empty(${'islocal'.$i}) ? '' : 1;
$isneed = empty(${'del'.$i}) ? true : false;
$servermsg = str_replace("'",'',stripslashes(${'servermsg'.$i}));
$softurl = stripslashes(${'softurl'.$i});
if($servermsg=='')
{
$servermsg = 'download地址'.$i;
}
if($softurl != '')
{
if($islocal==1) $urls .= "{dede:link islocal='$islocal' text='{$servermsg}'} $softurl {/dede:link}\r\n" ;
else if($isneed) $urls .= "{dede:link text='$servermsg'} $softurl {/dede:link}\r\n";
else continue;
}
}
}
$urls = addslashes($urls);
找到
$iquery = "UPDATE `$addtable` SET typeid='$typeid',body='$body'{$inadd_f},redirecturl='$redirecturl',templet='$templet',userip='$useip' WHERE aid='$id'";
替换为:
$iquery = "UPDATE `$addtable` SET typeid='$typeid',body='$body'{$inadd_f},redirecturl='$redirecturl',templet='$templet',userip='$useip',softlinks ='$urls',needmoney = '$needmoney',daccess = '$daccess' WHERE aid='$id'";
至此本教程后台修改部分已经完毕,你学会了吗?接下来开始前台部分。
三、前台调用,和软件的前台调用方式一样,看以下代码
{dede:field name='softlinks'/}
这个就是调用download地址,打开的页面为软件模型的download页,在哪里可以判断到download的权限。这里就不多讲了,改完后就可以看到了。
有一种情况,就是有些网友希望没有download地址的话就不显示,这里可以提供一种办法。把如下代码复制到新闻源码里即可。
{dede:php}
$thisid = $refObj->Fields['aid'];
$totrow=$dsql->GetOne('select * from js_addonarticle where aid='.$thisid);
if($totrow['softlinks']!='')
{
echo "<a href=http://www.dede58.com/a/dedejq/\"/plus/下载.php?open=0&aid=".$thisid."&cid=1\" style=\"color:white\" target=\"_blank\">download地址</a>";
}
{/dede:php}
前台效果图
到这里,本教程全文完毕。 本文章网址:http://www.ppssdd.com/code/13029.html。转载请保留出处,谢谢合作!
android – 在webview已经获取文件后调用setDownloadListener onDownloadStart吗?
WebView是否会执行Http获取并下载完整文件然后调用我的onDownloadStart()方法并且我的代码再次下载文件?
在Android应用程序中使用的WebView中,我们需要处理下载PDF文件.我看到了我认为有意义的行为,但看起来很奇怪,所以我希望有人能为我验证.
设置WebView后,我们调用setDownloadListener()并创建一个新的DownloadListener来处理onDownloadStart()方法调用.在onDownloadStart()方法中,我们使用HttpURLConnection从我们的Web服务器获取资源.
在网络跟踪中,我看到为同一资源执行了两个Http Get请求.我假设这是因为webview首先对资源进行了Get,然后webview执行自己的处理并确定它无法呈现资源.然后webview调用onDownloadStart()方法,我们第二次检索资源.
SetDownloadListener的文档说:
Register the interface to be used when content can not be handled by
the rendering engine, and should be downloaded instead. This will
replace the current handler.
webview不知道它是否可以呈现资源,直到它从服务器获得响应并且可以读取返回的内容类型.因此,它必须首先执行GET或HEAD来读取响应头.因此,双重下载行为似乎是有道理的.
并且,一些跟进问题:
>这是一种常见情况吗?大多数从webview中下载文件的应用程序是否真的下载了两次文件? (这看起来很贵,但我认为可能会发生)
>有没有办法重新使用第一个请求中已下载的内容而不是再次请求它?
>为什么WebView在第一个请求而不是GET上使用Http HEAD方法? (我想这会使每个超链接都是一个两步过程,这也会很昂贵)
>有没有办法阻止额外的下载?也许使用shouldOverrideUrlLoading()来拦截请求?
解决方法:
当你开始回答你的3.问题时,它会更好:
我认为WebView对所有Ressources使用GET方法.只有在获得此请求的第一个http标头后,WebView才会检查是否有标题告诉“执行下载”
(例如Content-disposition:Attachment; filename = example.html等标题)
如果没有指向下载的标头,WebView将在其视图中显示加载和内容.
如果有下载标题,则调用onDownload(即使其值设置为“inline”).
对问题2的回答:
我认为在这种情况下,webview不会加载内容的内容.
目前我不知道重用现有请求的方法.
回答问题4
如果你覆盖了shouldInterceptRequest
就像在这个例子中:https://stackoverflow.com/a/29811280/2377961
你可以改变这种行为.
android – 未知的URL内容:// downloads / my_downloads
我正在使用Download manger下载一些多媒体文件并对其进行分类.我也在使用Crashlytics,这是一个错误,我经常在不同的设备和Android版本上得到它.我正在寻找你的解决方案/建议!
java.lang.IllegalArgumentException: UnkNown URL content://downloads/my_downloads
at android.content.ContentResolver.insert(ContentResolver.java:862)
at android.app.DownloadManager.enqueue(DownloadManager.java:1252)
at com.myapp.LessonFragment$DownloadClickListener.onClick(SourceFile:570)
at android.view.View.performClick(View.java:4262)
at android.view.View$PerformClick.run(View.java:17351)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(NativeStart.java)
您可以在下面看到我的代码:
private class DownloadClickListener implements View.OnClickListener {
@Override
public void onClick(View view) {
// Check if download manager available before request
if (!DownloadHelper.isDownloadManagerAvailable(getActivity())) {
// Build custom alert dialog
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.download_manager_disabled);
builder.setCancelable(false);
builder.setPositiveButton(R.string.ok, (dialog, which) -> {
dialog.dismiss();
});
// Create and display alert dialog
AlertDialog dialog = builder.create();
dialog.show();
return;
}
// display short toast on download clicked
Toast.makeText(getActivity(), R.string.lesson_download_start, Toast.LENGTH_SHORT).show();
// Get attach from view tag
Attache attache = (Attache) view.getTag();
// Get lesson using lesson id
Lesson lesson = new Select().from(Lesson.class)
.where(Condition.column("id").is(attache.getLessonId()))
.querySingle();
// Set file name from url and attache name
Uri uri = Uri.parse(attache.getFile());
String fileName = attache.getName() + '.'
+ MimeTypeMap.getFileExtensionFromUrl(attache.getFile());
// Check if path directory not exist and create it
String filePath = Environment.getExternalStorageDirectory() + "/myapp/" + lesson.getTitle() + "/";
File path = new File(filePath);
if (!path.exists() || !path.isDirectory()) {
if (!path.mkdirs()) {
Timber.e("Could not create path directory.");
}
}
// Check if file exist and then delete it
File file = new File(filePath, fileName);
if (file.exists() && file.isFile()) {
if (file.delete()) {
Timber.v("%s just deleted.", fileName);
}
}
// Create download manager request using url
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setTitle(attache.getName());
request.setDestinationInExternalPublicDir("/myapp/" + lesson.getTitle(), fileName);
// Using DownloadManager for download attache file
DownloadManager manager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
}
}
解决方法:
对于那些获得错误未知URI的人:content:// downloads / public_downloads.
我设法通过@Commonsware在this answer中给出一个提示来解决这个问题.我在GitHub上找到了类FileUtils.
这里的InputStream方法用于从Download目录中获取文件.
// DownloadsProvider
else if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri);
if (id != null && id.startsWith("raw:")) {
return id.substring(4);
}
String[] contentUriPrefixesToTry = new String[]{
"content://downloads/public_downloads",
"content://downloads/my_downloads",
"content://downloads/all_downloads"
};
for (String contentUriPrefix : contentUriPrefixesToTry) {
Uri contentUri = ContentUris.withAppendedId(Uri.parse(contentUriPrefix), Long.valueOf(id));
try {
String path = getDataColumn(context, contentUri, null, null);
if (path != null) {
return path;
}
} catch (Exception e) {}
}
// path Could not be retrieved using ContentResolver, therefore copy file to accessible cache using streams
String fileName = getFileName(context, uri);
File cacheDir = getDocumentCacheDir(context);
File file = generateFileName(fileName, cacheDir);
String destinationPath = null;
if (file != null) {
destinationPath = file.getAbsolutePath();
saveFileFromUri(context, uri, destinationPath);
}
return destinationPath;
}
c# – DownloadFile vs DownloadFileAsync
我尝试使用WebClient.DownloadFileAsync,但它不能像DownloadFile一样工作,请澄清,我说不清楚,因为我正在从我的网络下载文件,所以它几乎立即下载,提前感谢.
PS:是的我试过谷歌搜索和阅读,找不到我需要的答案.
解决方法
var client = new WebClient(); var uri = new Uri(address); client.DownloadFileCompleted += (sender,e) => Console.WriteLine("Finished"); client.DownloadFileAsync(uri,"Hamsters.txt");
原答案:
WebClient.DownloadFileAsync返回您需要等待的任务.像这样:
await WebClient.DownloadFileAsync(...)
DownloadFileAsync将触发异步操作并返回将在操作结束时完成的任务. await意味着等待该任务以异步方式结束,因此当您拥有DownloadFileAsync的结果时,它之后的代码将运行.
同步的DownloadFile将阻止调用它的线程.如果它是UI线程,那么是…您的应用程序将无法响应.如果它不是UI线程,那么它仍然会响应,但它的可伸缩性会降低(这意味着它使用线程等待而不是做工作,所以你的应用程序作为一个整体可以用相同数量的线程做得更少)
com.intellij.util.download.DownloadableFileDescription的实例源码
private void downloadJar(String jarUrl,String jarName) { final Project project = myModule.getProject(); final String dirPath = PropertiesComponent.getInstance(project).getValue("findjar.last.used.dir"); VirtualFile toSelect = dirPath == null ? null : LocalFileSystem.getInstance().findFileByIoFile(new File(dirPath)); final VirtualFile file = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(),project,toSelect); if (file != null) { PropertiesComponent.getInstance(project).setValue("findjar.last.used.dir",file.getPath()); final DownloadableFileService downloader = DownloadableFileService.getInstance(); final DownloadableFileDescription description = downloader.createFileDescription(jarUrl,jarName); final List<VirtualFile> jars = downloader.createDownloader(Arrays.asList(description),jarName) .downloadFilesWithProgress(file.getPath(),myEditorComponent); if (jars != null && jars.size() == 1) { Accesstoken token = WriteAction.start(); try { OrderEntryFix.addJarToRoots(jars.get(0).getPresentableurl(),myModule,myRef); } finally { token.finish(); } } } }
@Nullable @Override public List<Pair<VirtualFile,DownloadableFileDescription>> downloadWithProgress(@Nullable String targetDirectoryPath,@Nullable Project project,@Nullable JComponent parentComponent) { File dir; if (targetDirectoryPath != null) { dir = new File(targetDirectoryPath); } else { VirtualFile virtualDir = chooseDirectoryForFiles(project,parentComponent); if (virtualDir != null) { dir = VfsutilCore.virtualToIoFile(virtualDir); } else { return null; } } return downloadWithProcess(dir,parentComponent); }
private static List<Pair<File,DownloadableFileDescription>> movetoDir(List<Pair<File,DownloadableFileDescription>> downloadedFiles,final File targetDir) throws IOException { FileUtil.createDirectory(targetDir); List<Pair<File,DownloadableFileDescription>> result = new ArrayList<Pair<File,DownloadableFileDescription>>(); for (Pair<File,DownloadableFileDescription> pair : downloadedFiles) { final DownloadableFileDescription description = pair.getSecond(); final String fileName = description.generateFileName(new Condition<String>() { @Override public boolean value(String s) { return !new File(targetDir,s).exists(); } }); final File toFile = new File(targetDir,fileName); FileUtil.rename(pair.getFirst(),toFile); result.add(Pair.create(toFile,description)); } return result; }
/** * Download files from the specified URLs. * * @param urls The URLs of the files. * @param targetPath The path to download the file to. * @return The downloaded files. */ private Collection<VirtualFile> downloadFiles(final Collection<String> urls,final String targetPath) { final DownloadableFileService fileService = DownloadableFileService.getInstance(); final List<DownloadableFileDescription> fileDescriptions = ContainerUtil.map(urls,(u) -> toFileDescription(fileService,u)); @Nullable final List<VirtualFile> files = fileService .createDownloader(fileDescriptions,"") .downloadFilesWithProgress(targetPath,null,null); if (files == null || files.size() != fileDescriptions.size()) { throw LoggerUtils2.exception(this.logger,RuntimeException.class,"Not all files were downloaded!"); } return files; }
private void downloadJar(String jarUrl,jarName); final VirtualFile[] jars = downloader.createDownloader(Arrays.asList(description),myEditorComponent,jarName) .toDirectory(file.getPath()).download(); if (jars != null && jars.length == 1) { Accesstoken token = WriteAction.start(); try { OrderEntryFix.addJarToRoots(jars[0].getPresentableurl(),myRef); } finally { token.finish(); } } } }
@Override public List<Pair<VirtualFile,DownloadableFileDescription>> downloadAndReturnWithDescriptions() { VirtualFile dir = null; if (myDirectoryForDownloadedFilesPath != null) { File ioDir = new File(FileUtil.toSystemDependentName(myDirectoryForDownloadedFilesPath)); ioDir.mkdirs(); dir = LocalFileSystem.getInstance().refreshAndFindFileByPath(myDirectoryForDownloadedFilesPath); } if (dir == null) { dir = chooseDirectoryForFiles(); } if (dir != null) { return dodownload(dir); } return null; }
public FileDownloaderImpl(@NotNull List<? extends DownloadableFileDescription> fileDescriptions,@Nullable JComponent parentComponent,@NotNull String presentableDownloadName) { myProject = project; myFileDescriptions = fileDescriptions; myParentComponent = parentComponent; myDialogTitle = IdeBundle.message("progress.download.0.title",StringUtil.capitalize(presentableDownloadName)); }
@Nullable @Override public List<VirtualFile> downloadFilesWithProgress(@Nullable String targetDirectoryPath,@Nullable JComponent parentComponent) { final List<Pair<VirtualFile,DownloadableFileDescription>> pairs = downloadWithProgress(targetDirectoryPath,parentComponent); if (pairs == null) return null; List<VirtualFile> files = new ArrayList<VirtualFile>(); for (Pair<VirtualFile,DownloadableFileDescription> pair : pairs) { files.add(pair.getFirst()); } return files; }
@Nullable private List<Pair<VirtualFile,DownloadableFileDescription>> downloadWithProcess(final File targetDir,Project project,JComponent parentComponent) { final Ref<List<Pair<File,DownloadableFileDescription>>> localFiles = Ref.create(null); final Ref<IOException> exceptionRef = Ref.create(null); boolean completed = ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() { @Override public void run() { try { localFiles.set(download(targetDir)); } catch (IOException e) { exceptionRef.set(e); } } },myDialogTitle,true,parentComponent); if (!completed) { return null; } @SuppressWarnings("ThrowableResultOfMethodCallIgnored") Exception exception = exceptionRef.get(); if (exception != null) { final boolean tryAgain = IOExceptionDialog.showErrorDialog(myDialogTitle,exception.getMessage()); if (tryAgain) { return downloadWithProcess(targetDir,parentComponent); } return null; } return findVirtualFiles(localFiles.get()); }
public FileDownloaderImpl(final List<? extends DownloadableFileDescription> fileDescriptions,final @Nullable Project project,JComponent parent,@NotNull String presentableDownloadName) { myProject = project; myFileDescriptions = fileDescriptions; myParent = parent; myDialogTitle = IdeBundle.message("progress.download.0.title",StringUtil.capitalize(presentableDownloadName)); }
@Override public VirtualFile[] download() { final List<Pair<VirtualFile,DownloadableFileDescription>> pairs = downloadAndReturnWithDescriptions(); if (pairs == null) return null; List<VirtualFile> files = new ArrayList<VirtualFile>(); for (Pair<VirtualFile,DownloadableFileDescription> pair : pairs) { files.add(pair.getFirst()); } return VfsutilCore.toVirtualFileArray(files); }
private static File generateName(DownloadableFileDescription info,final File dir) { final String fileName = info.generateFileName(new Condition<String>() { @Override public boolean value(String s) { return !new File(dir,s).exists(); } }); return new File(dir,fileName); }
@Nullable DownloadableFileDescription getSourcesDescription();
@Nullable DownloadableFileDescription getDocumentationDescription();
private static void deleteFiles(final List<Pair<File,DownloadableFileDescription>> pairs) { for (Pair<File,DownloadableFileDescription> pair : pairs) { FileUtil.delete(pair.getFirst()); } }
@Nullable @Override public List<Pair<VirtualFile,DownloadableFileDescription>> downloadAndReturnWithDescriptions() { return downloadWithProgress(myDirectoryForDownloadedFilesPath,myProject,myParentComponent); }
@Nullable DownloadableFileDescription getSourcesDescription();
@Nullable DownloadableFileDescription getDocumentationDescription();
private static void deleteFiles(final List<Pair<File,DownloadableFileDescription> pair : pairs) { FileUtil.delete(pair.getFirst()); } pairs.clear(); }
/** * Gets the file description of the specified URL. * * @param fileService The file service. * @param url The URL. * @return The file description. */ private DownloadableFileDescription toFileDescription(final DownloadableFileService fileService,final String url) { final String filename = FilenameUtils.getName(url); return fileService.createFileDescription(url,filename); }
今天的关于织梦CMS新闻模型整合download功能——可判断点数,会员组等download权限和织梦cms怎么样的分享已经结束,谢谢您的关注,如果想了解更多关于android – 在webview已经获取文件后调用setDownloadListener onDownloadStart吗?、android – 未知的URL内容:// downloads / my_downloads、c# – DownloadFile vs DownloadFileAsync、com.intellij.util.download.DownloadableFileDescription的实例源码的相关知识,请在本站进行查询。
本文标签: