Skip to content

Commit c97a710

Browse files
committed
Merge branch 'master' of https://github.com/arduino/Arduino into test
2 parents c6da87f + afc9ad2 commit c97a710

File tree

7 files changed

+154
-18
lines changed

7 files changed

+154
-18
lines changed

app/src/processing/app/Base.java

+36-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import processing.app.debug.Compiler;
3333
import processing.app.debug.Target;
34+
import processing.app.tools.ZipDeflater;
3435
import processing.core.*;
3536
import static processing.app.I18n._;
3637

@@ -942,10 +943,20 @@ protected void rebuildSketchbookMenu(JMenu menu) {
942943
}
943944

944945

945-
public void rebuildImportMenu(JMenu importMenu) {
946-
//System.out.println("rebuilding import menu");
946+
public void rebuildImportMenu(JMenu importMenu, final Editor editor) {
947947
importMenu.removeAll();
948-
948+
949+
JMenuItem addLibraryMenuItem = new JMenuItem(_("Add Library..."));
950+
addLibraryMenuItem.addActionListener(new ActionListener() {
951+
public void actionPerformed(ActionEvent e) {
952+
Base.this.handleAddZipLibrary(editor);
953+
Base.this.onBoardOrPortChange();
954+
Base.this.rebuildImportMenu(Editor.importMenu, editor);
955+
}
956+
});
957+
importMenu.add(addLibraryMenuItem);
958+
importMenu.addSeparator();
959+
949960
// reset the set of libraries
950961
libraries = new HashSet<File>();
951962

@@ -997,7 +1008,7 @@ public void onBoardOrPortChange() {
9971008
}
9981009

9991010

1000-
public void rebuildBoardsMenu(JMenu menu) {
1011+
public void rebuildBoardsMenu(JMenu menu, final Editor editor) {
10011012
//System.out.println("rebuilding boards menu");
10021013
menu.removeAll();
10031014
ButtonGroup group = new ButtonGroup();
@@ -2362,4 +2373,25 @@ static protected void listFiles(String basePath,
23622373
}
23632374
}
23642375
}
2376+
2377+
2378+
public void handleAddZipLibrary(Editor editor) {
2379+
String prompt = _("Select a zip file containing the library you'd like to add");
2380+
FileDialog fd = new FileDialog(editor, prompt, FileDialog.LOAD);
2381+
fd.setDirectory(System.getProperty("user.home"));
2382+
fd.setVisible(true);
2383+
2384+
String directory = fd.getDirectory();
2385+
String filename = fd.getFile();
2386+
if (filename == null) return;
2387+
2388+
File sourceFile = new File(directory, filename);
2389+
try {
2390+
ZipDeflater zipDeflater = new ZipDeflater(sourceFile, getSketchbookLibrariesFolder());
2391+
zipDeflater.deflate();
2392+
editor.statusNotice(_("Library added to your libraries. Check \"Import library\" menu"));
2393+
} catch (IOException e) {
2394+
editor.statusError(e);
2395+
}
2396+
}
23652397
}

app/src/processing/app/Editor.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void windowActivated(WindowEvent e) {
177177
// re-add the sub-menus that are shared by all windows
178178
fileMenu.insert(sketchbookMenu, 2);
179179
fileMenu.insert(examplesMenu, 3);
180-
sketchMenu.insert(importMenu, 4);
180+
//sketchMenu.insert(importMenu, 4);
181181
toolsMenu.insert(boardsMenu, numTools);
182182
toolsMenu.insert(serialMenu, numTools + 1);
183183
}
@@ -188,7 +188,7 @@ public void windowDeactivated(WindowEvent e) {
188188
// System.err.println("deactivate"); // not coming through
189189
fileMenu.remove(sketchbookMenu);
190190
fileMenu.remove(examplesMenu);
191-
sketchMenu.remove(importMenu);
191+
//sketchMenu.remove(importMenu);
192192
toolsMenu.remove(boardsMenu);
193193
toolsMenu.remove(serialMenu);
194194
}
@@ -627,7 +627,7 @@ public void actionPerformed(ActionEvent e) {
627627

628628
if (importMenu == null) {
629629
importMenu = new JMenu(_("Import Library..."));
630-
base.rebuildImportMenu(importMenu);
630+
base.rebuildImportMenu(importMenu, this);
631631
}
632632
sketchMenu.add(importMenu);
633633

@@ -680,7 +680,7 @@ public void actionPerformed(ActionEvent e) {
680680

681681
if (boardsMenu == null) {
682682
boardsMenu = new JMenu(_("Board"));
683-
base.rebuildBoardsMenu(boardsMenu);
683+
base.rebuildBoardsMenu(boardsMenu, this);
684684
}
685685
menu.add(boardsMenu);
686686

app/src/processing/app/Resources_fr.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ msgstr "Couper"
216216

217217
#: Editor.java:1143 Editor.java:2660
218218
msgid "Copy"
219-
msgstr "Coller"
219+
msgstr "Copier"
220220

221221
#: Editor.java:1151 Editor.java:2668
222222
msgid "Copy for Forum"

app/src/processing/app/Resources_fr.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Redo=R\u00e9tablir
158158
Cut=Couper
159159

160160
#: Editor.java:1143 Editor.java:2660
161-
Copy=Coller
161+
Copy=Copier
162162

163163
#: Editor.java:1151 Editor.java:2668
164164
Copy\ for\ Forum=Copier pour le forum
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package processing.app.tools;
2+
3+
import java.io.File;
4+
import java.io.FileOutputStream;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.util.Enumeration;
8+
import java.util.Random;
9+
import java.util.zip.ZipEntry;
10+
import java.util.zip.ZipException;
11+
import java.util.zip.ZipFile;
12+
13+
public class ZipDeflater {
14+
15+
private final ZipFile zipFile;
16+
private final File destFolder;
17+
18+
public ZipDeflater(File file, File destFolder) throws ZipException, IOException {
19+
this.destFolder = destFolder;
20+
this.zipFile = new ZipFile(file);
21+
}
22+
23+
public void deflate() throws IOException {
24+
String folderName = tempFolderNameFromZip();
25+
26+
File folder = new File(destFolder, folderName);
27+
28+
if (!folder.mkdir()) {
29+
throw new IOException("Unable to create folder " + folderName);
30+
}
31+
32+
Enumeration<? extends ZipEntry> entries = zipFile.entries();
33+
while (entries.hasMoreElements()) {
34+
ZipEntry entry = entries.nextElement();
35+
ensureFoldersOfEntryExist(folder, entry);
36+
File entryFile = new File(folder, entry.getName());
37+
if (entry.isDirectory()) {
38+
entryFile.mkdir();
39+
} else {
40+
FileOutputStream fos = null;
41+
InputStream zipInputStream = null;
42+
try {
43+
fos = new FileOutputStream(entryFile);
44+
zipInputStream = zipFile.getInputStream(entry);
45+
byte[] buffer = new byte[1024 * 4];
46+
int len = -1;
47+
while ((len = zipInputStream.read(buffer)) != -1) {
48+
fos.write(buffer, 0, len);
49+
}
50+
} finally {
51+
if (fos != null) {
52+
fos.close();
53+
}
54+
if (zipInputStream != null) {
55+
zipInputStream.close();
56+
}
57+
}
58+
}
59+
}
60+
61+
// Test.zip may or may not contain Test folder. We use zip name to create libraries folder. Therefore, a contained Test folder is useless and must be removed
62+
ensureOneLevelFolder(folder);
63+
}
64+
65+
private void ensureFoldersOfEntryExist(File folder, ZipEntry entry) {
66+
String[] parts = entry.getName().split("/");
67+
File current = folder;
68+
for (int i = 0; i < parts.length - 1; i++) {
69+
current = new File(current, parts[i]);
70+
current.mkdir();
71+
}
72+
}
73+
74+
private void ensureOneLevelFolder(File folder) {
75+
File[] files = folder.listFiles();
76+
if (files.length == 1 && files[0].isDirectory()) {
77+
File tempFile = new File(files[0].getPath() + new Random().nextInt(1000));
78+
files[0].renameTo(tempFile);
79+
for (File file : tempFile.listFiles()) {
80+
file.renameTo(new File(folder, file.getName()));
81+
}
82+
tempFile.delete();
83+
}
84+
}
85+
86+
private String tempFolderNameFromZip() {
87+
String folderName = zipFile.getName();
88+
if (folderName.lastIndexOf(".") != -1) {
89+
folderName = folderName.substring(0, folderName.lastIndexOf("."));
90+
}
91+
if (folderName.lastIndexOf(File.separator) != -1) {
92+
folderName = folderName.substring(folderName.lastIndexOf(File.separator) + 1);
93+
}
94+
return folderName;
95+
}
96+
97+
}

build/shared/revisions.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
ARDUINO 1.0.5 - 2013.03.29
2+
ARDUINO 1.0.5 - 2013.04.08
33

44
[core]
55

@@ -15,6 +15,10 @@ ARDUINO 1.0.5 - 2013.03.29
1515

1616
* Upgrades to WiFi firmwares
1717

18+
[ide]
19+
20+
* Backport from 1.5: install Library from file
21+
1822
ARDUINO 1.0.4 - 2013.03.11
1923

2024
[core]

libraries/GSM/examples/GsmWebClient/GsmWebClient.ino

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Web client
33
44
This sketch connects to a website through a GSM shield. Specifically,
5-
this example downloads the URL "http://arduino.cc/" and prints it
6-
to the Serial monitor.
5+
this example downloads the URL "http://arduino.cc/asciilogo.txt" and
6+
prints it to the Serial monitor.
77
88
Circuit:
99
* GSM shield attached to an Arduino
@@ -34,7 +34,7 @@ GSM gsmAccess;
3434

3535
// URL, path & port (for example: arduino.cc)
3636
char server[] = "arduino.cc";
37-
char path[] = "/";
37+
char path[] = "/asciilogo.txt";
3838
int port = 80; // port 80 is the default for HTTP
3939

4040
void setup()
@@ -48,13 +48,13 @@ void setup()
4848
Serial.println("Starting Arduino web client.");
4949
// connection state
5050
boolean notConnected = true;
51-
51+
5252
// After starting the modem with GSM.begin()
5353
// attach the shield to the GPRS network with the APN, login and password
5454
while(notConnected)
5555
{
5656
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
57-
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
57+
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
5858
notConnected = false;
5959
else
6060
{
@@ -72,7 +72,10 @@ void setup()
7272
// Make a HTTP request:
7373
client.print("GET ");
7474
client.print(path);
75-
client.println(" HTTP/1.0");
75+
client.println(" HTTP/1.1");
76+
client.print("Host: ");
77+
client.println(server);
78+
client.println("Connection: close");
7679
client.println();
7780
}
7881
else
@@ -91,7 +94,7 @@ void loop()
9194
char c = client.read();
9295
Serial.print(c);
9396
}
94-
97+
9598
// if the server's disconnected, stop the client:
9699
if (!client.available() && !client.connected())
97100
{

0 commit comments

Comments
 (0)