?? fxdownload.m
字號:
urlwrite(downloadFileURL,fullfile(downloadDir,[filename{1} fe{1}]));
unzipfilenames='';
end
%point to the download directory
cd(downloadDir);
%==========================================================================
function d = relevantHtmlInfo(htmlText,fileid,filename,dirname,downloadDir,contributorId,unzipfilenames)
%RELEVANTHTMLINFO Get the relevant information in a structure.
d.dirname = dirname;
d.filename = filename;
d.title = regexp(htmlText,'<tr><td width=70% class=headercell height=20> (.*?) ','tokens','once');
d.fullfilename = downloadDir;
d.description = strrep(regexprep(regexp(htmlText,'<td width="456" class="lnwrp">(.*?)</td>','tokens','once'),'\n','<br>'),'<br><br>','<br>');
%Category
category = regexp(htmlText,'objectType=Category">(.*?)</a>','tokens');
if ~isempty(category)
d.category = regexprep(category{length(category)}{1},'[/,\s]','_');
else
d.category = '';
end
categoryid = regexp(htmlText,'loadCategory\.do\?objectId=(\d+)&objectType=Category','tokens');
d.categoryurl = ['http://www.mathworks.com/matlabcentral/fileexchange/loadCategory.do?objectId=' categoryid{length(categoryid)}{1} '&objectType=Category'];
d.author = strrep(regexp(htmlText,['<a .*objectId=' contributorId{1} '">(.*?)</a>'],'tokens','once'),' ','_');
d.authorurl = ['http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectType=author&objectId=' contributorId{1}];
d.date = datenum(clock);
d.ratinglink = ['http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=' sprintf('%.0f',fileid) '&objectType=file#review_submission'];
d.link = strcat('http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=', sprintf('%.0f',fileid));
%Thumbnail url
thumbnailUrl = regexp(htmlText,'<td id="scrnshot" valign="top">.*imgName=(.*?)" onClick','tokens','once');
if ~isempty(thumbnailUrl)
d.thumbnailUrl = strcat(['http://www.mathworks.com/matlabcentral/files/' sprintf('%.0f',fileid) '/'], thumbnailUrl{1});
else
d.thumbnailUrl = '';
end
lastmoddate = regexp(htmlText,'<td width=100 valign="top">(.*?)<\/td>','tokens','once');
d.lastmoddate = lastmoddate;
%Finding Links Text
token = regexp(htmlText,'What are<br/>Published M-files.*\< <td height="15" colspan="2">(.*?)</td>','match');
if ~isempty(token)
%Findig links
fileurls = regexp(token{1},'(\w+)\.htm','match');
%Finding Links Titles
fileurlnames = regexp(token{1},'w.focus\();">(.*?)<','tokens');
counter = 1;
for j=1:length(unzipfilenames)
x = regexp(unzipfilenames{j},'(\w+)\.htm','match');
if ~isempty(x)
for i=1:length(fileurls)
if strcmp(x,fileurls{i})
d.fileurls{i} = unzipfilenames{j};
d.fileurlnames(i) = fileurlnames{i};
end
end
counter=counter+1;
end
end
else
d.fileurls = '';
d.fileurlnames = '';
end
%==========================================================================
function writeIndex(indexPath,filename,downloadDir,intro,d)
%WRITEINDEX Build a html page.
s = [];
s{1} = '<html><head><title>File Exchange Downloads: My downloads</title>';
% No margin above paragraphs in the description section.
s{end+1} = '<link rel="stylesheet" href="http://www-internal.mathworks.com/devel/sharedemos/styles.css" type="text/css" />';
s{end+1} = '</head>';
s{end+1} = '<body>';
s{end+1} = '<h3 align="right" STYLE="font-size:10pt;color:red">';
s{end+1} = sprintf('Last Updated on: %s',datestr(clock,0));
s{end+1} = '</h3>';
s{end+1} = '<div class="main_intro">';
s{end+1} = intro;
s{end+1} = '</div>';
s{end+1} = '<div>';
s{end+1} = '<table cellspacing="0" border="0" width="100%" id="table1">';
s{end+1} = '<tr>';
s{end+1} = '<td valign="middle" align="left" width="33%">';
s{end+1} = ['<a href="matlab: updatefxindex(''' fullfile(indexPath,filename) ''');" style="text-decoration:none"><b>Refresh</b></a>'];
s{end+1} = '</td>';
s{end+1} = '<td valign="middle" align="center" width="33%">';
[dirPath fxdirname] = fileparts(fileparts(indexPath));
if ~strcmp(fxdirname,'fxdownloads')
s{end+1} = ['<a href="matlab: checkforUpdates(''' fullfile(indexPath,filename) ''',1);" style="text-decoration:none"><b>Check for Updates</b></a>'];
else
s{end+1} =['<h3 align="center"><a href="matlab: fxgoup(''' fullfile(indexPath,filename) ''')" style="text-decoration:none" title="Go up one level">' ...
'<img src="file:///' strrep(which('fxreturn.png'),'\','/') '"' ...
' style="border:0">My downloads</a>'];
s{end+1} = '</h3>';
end
s{end+1} = '</td>';
s{end+1} = '<td valign="middle" align="right" width="33%">';
s{end+1} = ['<form method="post" action="matlab:fxsearch"><h3>Search: <input type="text" name="searchstr" value=""> <input type="submit" value="Submit"><br>' ...
'<a href="matlab: fxsearch(''recent'',15,1);" style="text-decoration:none;font-size:small">Top 15 recent files</a>, ' ...
'<a href="matlab: fxsearch(''popular'',15,1);" style="text-decoration:none;font-size:small">Top 15 popular files</a> </h3></form>'];
s{end+1} = '</td>';
s{end+1} = '</tr>';
s{end+1} = '</table>';
s{end+1} = '<table cellspacing="0" class="t1" id="table2">';
s{end+1} = '<tr>';
s{end+1} = '<td valign="top" class="td1">';
%Thumbnail
if ~isempty(d.thumbnailUrl)
s{end+1} = sprintf('<img src="%s" border="0" width="84" height="64">',d.thumbnailUrl);
else
s{end+1} = ' ';
end
s{end+1} = '</td>';
s{end+1} = '<td valign="top" class="td1">';
% Title
if ~isempty(d.title)
demotitle = d.title{1};
else
demotitle = d.filename{1};
end
s{end+1} = sprintf('<h2><a href="%s">%s</a>', ...
d.link,demotitle);
s{end+1} = sprintf('<font style="font-size:x-small">(<a href="matlab: addpath(''%s'')" style="text-decoration:none">addpath</a>)</font></h2>',downloadDir);
% Gray info line
s{end+1} = '<span class="dim"">';
% Author
if ~isempty(d.author{1})
s{end+1} = sprintf('<a href="%s">%s</a>, ', ...
d.authorurl,strrep(d.author{1},'_',' '));
end
%Category
if ~isempty(d.category)
s{end+1} = sprintf('<a href="%s">%s</a>, ', ...
d.categoryurl,d.category);
end
s{end+1} = sprintf('Updated on %s',datestr(d.date,0));
s{end+1} = '</span><br>';
%Local directory name
s{end+1} = '<span class="dim">';
s{end+1} = sprintf('CD to Local directory: <a href="matlab: cd(''%s'')">%s</a>, ',downloadDir,d.dirname);
s{end+1} = sprintf('<a href="matlab: web(''%s'')">Summary Page</a>',fullfile(downloadDir,'fxsummary.html'));
s{end+1} = '</span><br>';
%Related html links for a file
if ~isempty(d.fileurls)
s{end+1} = '<p><ul>';
for j=1:length(d.fileurls)
s{end+1} = sprintf('<li><a href="file:///%s">%s</a></li>',strrep(d.fileurls{j},'\','/'), d.fileurlnames{j});
end
s{end+1} = '</p></ul>';
end
% Description
s{end+1} = '<br>';
if ~isempty(d.description)
s{end+1} = d.description{1};
end
%Let the user Rate the downloaded file file
s{end+1} = ['<br><a href="' d.ratinglink '"><b>Review this file</b></a><br>'];
s{end+1} = '<br>';
if ~strcmp(fxdirname,'fxdownloads')
s{end+1} = ['<a href="matlab: deletefile(''' downloadDir ''',1);" style="text-decoration:none"><b>Delete</b></a>'];
else
s{end+1} = ['<a href="matlab: deletefile(''' downloadDir ''');" style="text-decoration:none"><b>Delete</b></a>'];
end
s{end+1} = '<br><br>';
s{end+1} = '</td>';
s{end+1} = '</tr>';
% Make web page
%Check if any file is downloaded. If downloaded sort the list according to
%the date and append it at the bottom.
allhtmllist = getallHtmlList(indexPath);
temp = getSummary(allhtmllist);
for j = 1:length(temp)
if strcmp(fxdirname,'fxdownloads') && ~isempty(temp{j})
x = regexp(temp{j},'<a href="matlab: (deletefile.*?);','tokens','once');
y = regexprep(x{1},')',',1)');
temp{j} = strrep(temp{j},x{1},y);
end
s{end+1} = temp{j};
end
s{end+1} = '</table>';
s{end+1} = '<p>';
s{end+1} = '</div></body></html>';
% Save out the file
[fid,message] = fopen(fullfile(indexPath,filename),'w+');
if fid > 0
for n = 1:length(s)
fprintf(fid,'%s\n',s{n});
end
fclose(fid);
else
error(message);
end
%Open the index file
%web([indexPath filename],'-new');
%==========================================================================
function createSummaryPage(indexPath,filename,downloadDir)
%CREATESUMMARYPAGE Create a fxsummary.html page.
%Create a summary page for each individual download and save it in download
%directory of each downlaod
temp=[];
intro = '<h1><center>Summary</center></h1>';
temp{1} = '<html><head><title>File Exchange Downloads: Summary Page</title>';
% No margin above paragraphs in the description section.
temp{end+1} = '<link rel="stylesheet" href="http://www-internal.mathworks.com/devel/sharedemos/styles.css" type="text/css" />';
temp{end+1} = '</head>';
temp{end+1} = '<body>';
temp{end+1} = '<h3 align="right" STYLE="font-size:10pt;color:red">';
temp{end+1} = sprintf('Last Updated on: %s',datestr(clock,0));
temp{end+1} = '</h3>';
temp{end+1} = '<div class="main_intro">';
temp{end+1} = intro;
temp{end+1} = '</div>';
temp{end+1} = '<div>';
temp{end+1} =['<h3 align="center"><a href="matlab: fxgoup(''' fullfile(downloadDir,'fxsummary.html') ''')" style="text-decoration:none" title="Go up one level">' ...
'<img src="file:///' strrep(which('fxreturn.png'),'\','/') '"' ...
' style="border:0">My downloads</a>'];
temp{end+1} = '</h3>';
[fid,message] = fopen(fullfile(indexPath,filename),'r');
if fid > 0
htmlText = fread(fid,'char=>char')';
fclose(fid);
else
error(message);
end
token = regexp(htmlText,'(<table cellspacing="0" class="t1" id="table2">.*?</tr>)','match','once');
x = regexp(token,'deletefile(.*);','tokens','once');
y = regexprep(x{1},',1)',')');
temp{end+1} = strrep(token,x{1},y);
temp{end+1} = '</table>';
temp{end+1} = '<p>';
temp{end+1} = '</div></body></html>';
[fid,message] = fopen(fullfile(downloadDir,'fxsummary.html'), 'w+');
if fid > 0
for i=1:length(temp)
fprintf(fid,'%s\n',temp{i});
end
fclose(fid);
else
error(message)
end
%==========================================================================
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -