Exemplo n.º 1
0
  public FileData decryptFile(FileData fd) throws IOException {
    ByteArrayInputStream input = fd.getInputStream();
    ByteArrayOutputStream output = new ByteArrayOutputStream();

    BASE64Decoder base64 = new BASE64Decoder();
    byte[] bytearr = base64.decodeBuffer(input);
    input = new ByteArrayInputStream(bytearr);

    Cipher cipher = null;
    try {
      cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
    } catch (Exception e) {
      throw new IOException(e);
    }

    try {
      cipher.init(Cipher.DECRYPT_MODE, key);
    } catch (Exception e) {
      throw new IOException(e);
    }

    int length = -1;
    CipherInputStream stream = new CipherInputStream(input, cipher);
    while ((length = stream.read(bytearr)) != -1) {
      output.write(bytearr, 0, length);
    }
    output.close();

    String path = fd.getPath().replaceAll("\\.(.*)_enc", "\\.$1");
    return new FileData(path, output.toByteArray());
  }
Exemplo n.º 2
0
  public EobFiles(String eobPath) {
    File directory = new File(eobPath);
    File[] filesInDir = directory.listFiles();
    if (filesInDir == null) {
      return;
    }

    for (File file : filesInDir) {
      if (file.isFile()) {
        if (file.getName().toLowerCase().endsWith(".pak")) {
          PakFile pakFile = new PakFile(file.getPath(), debug);
          for (PakFile.FilePos filePos : pakFile.getFiles()) {
            FileData fileData = new FileData();
            fileData.name = filePos.name;
            fileData.path = file.getPath() + " : " + filePos.name;
            fileData.data = filePos.data;
            files.put(filePos.name.toLowerCase(), fileData);
          }
        } else {
          FileData fileData = new FileData();
          fileData.name = file.getName();
          fileData.path = file.getPath();
          files.put(file.getName().toLowerCase(), fileData);
        }
      }
    }
  }
Exemplo n.º 3
0
  /**
   * Serialize the FileData.
   *
   * @param parentElement The parent element for the FileData.
   * @param fileData The FileData to serialize.
   */
  private void serializeFileData(final Element parentElement, final FileData fileData) {
    CueSheetToXmlSerializer.logger.entering(
        CueSheetToXmlSerializer.class.getCanonicalName(),
        "serializeFileData(Element,FileData)",
        new Object[] {parentElement, fileData});
    Document doc = parentElement.getOwnerDocument();
    Element fileElement = doc.createElementNS(this.namespace, "file");
    parentElement.appendChild(fileElement);

    addAttribute(fileElement, "file", fileData.getFile());
    addAttribute(fileElement, "type", fileData.getFileType());

    for (TrackData trackData : fileData.getTrackData()) {
      serializeTrackData(fileElement, trackData);
    }
    CueSheetToXmlSerializer.logger.exiting(
        CueSheetToXmlSerializer.class.getCanonicalName(), "serializeFileData(Element,FileData)");
  }
Exemplo n.º 4
0
 public TweetDao tweetWithImg(TweetDao t) throws IOException {
   FileData awr = fileSaver.saveFileFromUrl(t.getTwitterImageUrl());
   if (awr != null) t.setImagePath(awr.getImgPath());
   return t;
 }
Exemplo n.º 5
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    final FileData fd = this.getItem(position);

    if (convertView == null) {
      convertView = inflater.inflate(R.layout.book_shelf_colum, null);
    }

    ImageView file_mode = (ImageView) convertView.findViewById(R.id.file_mode);
    if (BooksAPI.isBook(fd.getFullPath())) {
      file_mode.setImageResource(R.drawable.bookmark);
    } else if (BooksAPI.isImage(fd.getName())) {
      file_mode.setImageResource(R.drawable.image);
    } else {
      file_mode.setImageResource(R.drawable.folder);
    }

    TextView file_button = (TextView) convertView.findViewById(R.id.file_button);
    file_button.setText(fd.getName());
    file_button.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (BooksAPI.isBook(fd.getFullPath())) {
              // falseならお絵かき帳ディレクトリ
              Intent intent = new Intent(context, DrawBookActivity.class);
              intent.putExtra("path", fd.getFullPath() + "/");
              context.startActivity(intent);
              context.finish();
            } else if (BooksAPI.isImage(fd.getName())) {
              Intent intent = new Intent(context, MainActivity.class);
              intent.putExtra("path", fd.getPath() + "/");
              intent.putExtra("newflag", false); // 新規押した時、フォルダのパス
              intent.putExtra("name", fd.getName());
              context.startActivity(intent);
            } else {
              // trueならば本棚ディレクトリ
              lv_activity.ListViewLoader(lv_activity.listView, fd.getFullPath());
              lv_activity.pathChange(fd.getFullPath() + "/");
            }
          }
        });

    Button delete = (Button) convertView.findViewById(R.id.delete_button);
    delete.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            new AlertDialog.Builder(context)
                .setMessage("本当に削除しますか?")
                .setPositiveButton(
                    "OK",
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        new File(lv_activity.current_path);
                        File file = new File(fd.getFullPath());
                        if (!(file.delete())) {
                          Toast.makeText(context, "削除できませんでした", Toast.LENGTH_SHORT).show();
                        }
                        lv_activity.ListViewLoader(lv_activity.listView, lv_activity.current_path);
                      }
                    })
                .setNegativeButton(
                    "キャンセル",
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        // 何もしない
                      }
                    })
                .show();
            // Toast.makeText(context,"中にディレクトリが存在するので削除できません",Toast.LENGTH_SHORT).show();
          }
        });

    return convertView;
  }
Exemplo n.º 6
0
  /**
   * view command
   *
   * @param shell shell
   * @param repositoryTab repository tab
   * @param fileData file to view
   * @param revision revision to view
   */
  CommandView(
      final Shell shell,
      final RepositoryTab repositoryTab,
      final FileData fileData,
      final String revision) {
    Composite composite, subComposite;
    Label label;
    Button button;
    Listener listener;

    // initialize variables
    this.repositoryTab = repositoryTab;
    this.fileData = fileData;

    // get display
    display = shell.getDisplay();
    clipboard = new Clipboard(display);

    // add files dialog
    dialog = Dialogs.open(shell, "View: " + fileData.getFileName(), new double[] {1.0, 0.0}, 1.0);

    composite = Widgets.newComposite(dialog);
    composite.setLayout(new TableLayout(new double[] {0.0, 1.0, 0.0}, 1.0, 4));
    Widgets.layout(composite, 0, 0, TableLayoutData.NSWE, 0, 0, 4);
    {
      subComposite = Widgets.newComposite(composite);
      subComposite.setLayout(new TableLayout(1.0, new double[] {0.0, 1.0}));
      Widgets.layout(subComposite, 0, 0, TableLayoutData.WE);
      {
        label = Widgets.newLabel(subComposite, "Revision:");
        Widgets.layout(label, 0, 0, TableLayoutData.W);

        widgetRevision = Widgets.newSelect(subComposite);
        widgetRevision.setEnabled(false);
        Widgets.layout(widgetRevision, 0, 1, TableLayoutData.WE);
        Widgets.addModifyListener(
            new WidgetListener(widgetRevision, data) {
              public void modified(Control control) {
                Widgets.setEnabled(control, (data.revisionNames != null));
              }
            });
        widgetRevision.setToolTipText("Revision to view.");

        widgetRevisionPrev = Widgets.newButton(subComposite, Onzen.IMAGE_ARROW_LEFT);
        widgetRevisionPrev.setEnabled(false);
        Widgets.layout(widgetRevisionPrev, 0, 2, TableLayoutData.NSW);
        Widgets.addModifyListener(
            new WidgetListener(widgetRevisionPrev, data) {
              public void modified(Control control) {
                Widgets.setEnabled(
                    control,
                    (data.revisionNames != null) && (widgetRevision.getSelectionIndex() > 0));
              }
            });
        widgetRevisionPrev.setToolTipText("Show previous revision.");

        widgetRevisionNext = Widgets.newButton(subComposite, Onzen.IMAGE_ARROW_RIGHT);
        widgetRevisionNext.setEnabled(false);
        Widgets.layout(widgetRevisionNext, 0, 3, TableLayoutData.NSW);
        Widgets.addModifyListener(
            new WidgetListener(widgetRevisionNext, data) {
              public void modified(Control control) {

                Widgets.setEnabled(
                    control,
                    (data.revisionNames != null)
                        && (widgetRevision.getSelectionIndex() < data.revisionNames.length - 1));
              }
            });
        widgetRevisionNext.setToolTipText("Show next revision.");
      }

      subComposite = Widgets.newComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
      subComposite.setLayout(new TableLayout(1.0, new double[] {0.0, 1.0}));
      Widgets.layout(subComposite, 1, 0, TableLayoutData.NSWE);
      {
        widgetLineNumbers = Widgets.newTextView(subComposite, SWT.RIGHT | SWT.BORDER | SWT.MULTI);
        widgetLineNumbers.setForeground(Onzen.COLOR_GRAY);
        Widgets.layout(widgetLineNumbers, 0, 0, TableLayoutData.NS, 0, 0, 0, 0, 60, SWT.DEFAULT);
        Widgets.addModifyListener(
            new WidgetListener(widgetLineNumbers, data) {
              public void modified(Control control) {
                control.setForeground((data.lines != null) ? null : Onzen.COLOR_GRAY);
              }
            });

        widgetText = Widgets.newTextView(subComposite, SWT.LEFT | SWT.BORDER | SWT.MULTI);
        widgetText.setForeground(Onzen.COLOR_GRAY);
        Widgets.layout(widgetText, 0, 1, TableLayoutData.NSWE);
        Widgets.addModifyListener(
            new WidgetListener(widgetText, data) {
              public void modified(Control control) {
                control.setForeground((data.lines != null) ? null : Onzen.COLOR_GRAY);
              }
            });
      }
      widgetHorizontalScrollBar = subComposite.getHorizontalBar();
      widgetVerticalScrollBar = subComposite.getVerticalBar();

      subComposite = Widgets.newComposite(composite);
      subComposite.setLayout(new TableLayout(1.0, new double[] {0.0, 1.0}));
      Widgets.layout(subComposite, 2, 0, TableLayoutData.NSWE);
      {
        label = Widgets.newLabel(subComposite, "Find:", SWT.NONE, Settings.keyFind);
        Widgets.layout(label, 0, 0, TableLayoutData.W);

        widgetFind = Widgets.newText(subComposite, SWT.SEARCH | SWT.ICON_CANCEL);
        widgetFind.setMessage("Enter text to find");
        Widgets.layout(widgetFind, 0, 1, TableLayoutData.WE);

        widgetFindPrev = Widgets.newButton(subComposite, Onzen.IMAGE_ARROW_UP);
        widgetFindPrev.setEnabled(false);
        Widgets.layout(widgetFindPrev, 0, 2, TableLayoutData.NSW);
        Widgets.addModifyListener(
            new WidgetListener(widgetFindPrev, data) {
              public void modified(Control control) {
                Widgets.setEnabled(control, (data.lines != null));
              }
            });
        widgetFindPrev.setToolTipText(
            "Find previous occurrence of text ["
                + Widgets.acceleratorToText(Settings.keyFindPrev)
                + "].");

        widgetFindNext = Widgets.newButton(subComposite, Onzen.IMAGE_ARROW_DOWN);
        widgetFindNext.setEnabled(false);
        Widgets.layout(widgetFindNext, 0, 3, TableLayoutData.NSW);
        Widgets.addModifyListener(
            new WidgetListener(widgetFindNext, data) {
              public void modified(Control control) {
                Widgets.setEnabled(control, (data.lines != null));
              }
            });
        widgetFindNext.setToolTipText(
            "Find next occurrence of text  ["
                + Widgets.acceleratorToText(Settings.keyFindNext)
                + "].");
      }
    }

    // buttons
    composite = Widgets.newComposite(dialog);
    composite.setLayout(new TableLayout(0.0, 1.0));
    Widgets.layout(composite, 1, 0, TableLayoutData.WE, 0, 0, 4);
    {
      button = Widgets.newButton(composite, "Save as...");
      Widgets.layout(
          button, 0, 0, TableLayoutData.W, 0, 0, 0, 0, SWT.DEFAULT, SWT.DEFAULT, 70, SWT.DEFAULT);
      button.addSelectionListener(
          new SelectionListener() {
            public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

            public void widgetSelected(SelectionEvent selectionEvent) {
              // get file name
              String fileName = Dialogs.fileSave(dialog, "Save file", "", new String[] {"*"});
              if (fileName == null) {
                return;
              }

              // check if file exists: overwrite or append
              File file = new File(fileName);
              if (file.exists()) {
                switch (Dialogs.select(
                    dialog,
                    "Confirmation",
                    String.format("File '%s' already exists.", fileName),
                    new String[] {"Overwrite", "Append", "Cancel"},
                    2)) {
                  case 0:
                    if (!file.delete()) {
                      Dialogs.error(dialog, "Cannot delete file!");
                      return;
                    }
                  case 1:
                    break;
                  case 2:
                    return;
                }
              }

              PrintWriter output = null;
              try {
                // open file
                output = new PrintWriter(new FileWriter(file, true));

                // write/append file
                for (String line : data.lines) {
                  output.println(line);
                }

                // close file
                output.close();
              } catch (IOException exception) {
                Dialogs.error(
                    dialog,
                    "Cannot write file '" + file.getName() + "' (error: " + exception.getMessage());
                return;
              } finally {
                if (output != null) output.close();
              }
            }
          });

      widgetClose = Widgets.newButton(composite, "Close");
      Widgets.layout(
          widgetClose,
          0,
          1,
          TableLayoutData.E,
          0,
          0,
          0,
          0,
          SWT.DEFAULT,
          SWT.DEFAULT,
          70,
          SWT.DEFAULT);
      widgetClose.addSelectionListener(
          new SelectionListener() {
            public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

            public void widgetSelected(SelectionEvent selectionEvent) {
              Settings.geometryView = dialog.getSize();

              Dialogs.close(dialog, false);
            }
          });
    }

    // listeners
    widgetRevision.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            Combo widget = (Combo) selectionEvent.widget;

            int index = widget.getSelectionIndex();
            if ((data.revisionNames != null)
                && (index >= 0)
                && (index < data.revisionNames.length)) {
              show(data.revisionNames[index]);
            }
          }
        });
    widgetRevisionPrev.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            int index = widgetRevision.getSelectionIndex();
            if (index > 0) {
              show(data.revisionNames[index - 1]);
            }
          }
        });
    widgetRevisionNext.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            int index = widgetRevision.getSelectionIndex();
            if ((data.revisionNames != null) && (index < data.revisionNames.length - 1)) {
              show(data.revisionNames[index + 1]);
            }
          }
        });

    listener =
        new Listener() {
          public void handleEvent(Event event) {
            StyledText widget = (StyledText) event.widget;
            int topIndex = widget.getTopIndex();
            // Dprintf.dprintf("%d %d",widget.getTopPixel(),widgetText.getTopPixel());

            widgetText.setTopIndex(topIndex);
            widgetText.setCaretOffset(widgetText.getOffsetAtLine(topIndex));
          }
        };
    widgetLineNumbers.addListener(SWT.KeyDown, listener);
    widgetLineNumbers.addListener(SWT.KeyUp, listener);
    widgetLineNumbers.addListener(SWT.MouseDown, listener);
    widgetLineNumbers.addListener(SWT.MouseUp, listener);
    widgetLineNumbers.addListener(SWT.MouseMove, listener);
    widgetLineNumbers.addListener(SWT.Resize, listener);

    listener =
        new Listener() {
          public void handleEvent(Event event) {
            StyledText widget = (StyledText) event.widget;
            int topIndex = widget.getTopIndex();
            // Dprintf.dprintf("widget=%s: %d",widget,widget.getTopIndex());

            widgetLineNumbers.setTopIndex(topIndex);
            widgetVerticalScrollBar.setSelection(topIndex);
          }
        };
    widgetText.addListener(SWT.KeyDown, listener);
    widgetText.addListener(SWT.KeyUp, listener);
    widgetText.addListener(SWT.MouseDown, listener);
    widgetText.addListener(SWT.MouseUp, listener);
    widgetText.addListener(SWT.MouseMove, listener);
    widgetText.addListener(SWT.Resize, listener);
    widgetText.addLineStyleListener(
        new LineStyleListener() {
          public void lineGetStyle(LineStyleEvent lineStyleEvent) {
            // Dprintf.dprintf("x %d %s",lineStyleEvent.lineOffset,lineStyleEvent.lineText);
            String findText = widgetFind.getText().toLowerCase();
            int findTextLength = findText.length();
            if (findTextLength > 0) {
              ArrayList<StyleRange> styleRangeList = new ArrayList<StyleRange>();
              int index = 0;
              while ((index = lineStyleEvent.lineText.toLowerCase().indexOf(findText, index))
                  >= 0) {
                styleRangeList.add(
                    new StyleRange(
                        lineStyleEvent.lineOffset + index,
                        findTextLength,
                        COLOR_VIEW_SEARCH_TEXT,
                        COLOR_VIEW_SEARCH_BACKGROUND));
                index += findTextLength;
              }
              lineStyleEvent.styles = styleRangeList.toArray(new StyleRange[styleRangeList.size()]);
              // Dprintf.dprintf("lineStyleEvent.styles=%d",lineStyleEvent.styles.length);
            } else {
              lineStyleEvent.styles = null;
            }
          }
        });
    widgetText.addKeyListener(
        new KeyListener() {
          public void keyPressed(KeyEvent keyEvent) {
            if (Widgets.isAccelerator(keyEvent, SWT.CTRL + 'c')) {
              Widgets.setClipboard(clipboard, widgetText.getSelectionText());
            }
          }

          public void keyReleased(KeyEvent keyEvent) {}
        });
    widgetHorizontalScrollBar.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            ScrollBar widget = (ScrollBar) selectionEvent.widget;
            int index = widget.getSelection();

            // sync text widget
            widgetText.setHorizontalIndex(index);
          }
        });
    widgetVerticalScrollBar.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            ScrollBar widget = (ScrollBar) selectionEvent.widget;
            int index = widget.getSelection();
            // Dprintf.dprintf("widget=%s: %d %d
            // %d",widget,widget.getSelection(),widget.getMinimum(),widget.getMaximum());

            // sync  number text widget, text widget
            widgetLineNumbers.setTopIndex(index);
            widgetText.setTopIndex(index);
          }
        });

    widgetFind.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {
            findNext(widgetText, widgetFind);
          }

          public void widgetSelected(SelectionEvent selectionEvent) {}
        });
    widgetFind.addKeyListener(
        new KeyListener() {
          public void keyPressed(KeyEvent keyEvent) {}

          public void keyReleased(KeyEvent keyEvent) {
            updateViewFindText(widgetText, widgetFind);
          }
        });
    widgetFindPrev.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            findPrev(widgetText, widgetFind);
          }
        });
    widgetFindNext.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            findNext(widgetText, widgetFind);
          }
        });

    KeyListener keyListener =
        new KeyListener() {
          public void keyPressed(KeyEvent keyEvent) {
            if (Widgets.isAccelerator(keyEvent, Settings.keyFind)) {
              widgetFind.forceFocus();
            } else if (Widgets.isAccelerator(keyEvent, Settings.keyFindPrev)) {
              Widgets.invoke(widgetFindPrev);
            } else if (Widgets.isAccelerator(keyEvent, Settings.keyFindNext)) {
              Widgets.invoke(widgetFindNext);
            }
          }

          public void keyReleased(KeyEvent keyEvent) {}
        };
    widgetText.addKeyListener(keyListener);
    widgetFind.addKeyListener(keyListener);
    widgetFindPrev.addKeyListener(keyListener);
    widgetFindNext.addKeyListener(keyListener);

    dialog.addListener(
        USER_EVENT_NEW_REVISION,
        new Listener() {
          public void handleEvent(Event event) {}
        });

    // show dialog
    Dialogs.show(dialog, Settings.geometryView, Settings.setWindowLocation);

    // start show file
    show(revision);

    // start add revisions (only if single file is seleccted)
    Background.run(
        new BackgroundRunnable(fileData, revision) {
          public void run(FileData fileData, final String revision) {
            // get revisions
            repositoryTab.setStatusText("Get revisions for '%s'...", fileData.getFileName());
            try {
              data.revisionNames = repositoryTab.repository.getRevisionNames(fileData);
            } catch (RepositoryException exception) {
              final String exceptionMessage = exception.getMessage();
              display.syncExec(
                  new Runnable() {
                    public void run() {
                      Dialogs.error(
                          dialog, String.format("Getting revisions fail: %s", exceptionMessage));
                    }
                  });
              return;
            } finally {
              repositoryTab.clearStatusText();
            }

            if (data.revisionNames.length > 0) {
              // add revisions
              if (!dialog.isDisposed()) {
                display.syncExec(
                    new Runnable() {
                      public void run() {
                        if (!widgetRevision.isDisposed()) {
                          int selectIndex = -1;
                          for (int z = 0; z < data.revisionNames.length; z++) {
                            widgetRevision.add(data.revisionNames[z]);
                            if ((revision != null) && revision.equals(data.revisionNames[z])) {
                              selectIndex = z;
                            }
                          }
                          widgetRevision.add(repositoryTab.repository.getLastRevision());
                          if ((revision != null)
                              && revision.equals(repositoryTab.repository.getLastRevision()))
                            selectIndex = data.revisionNames.length;
                          if (selectIndex == -1) selectIndex = data.revisionNames.length;
                          widgetRevision.select(selectIndex);
                        }

                        // notify modification
                        Widgets.modified(data);
                      }
                    });
              }
            }
          }
        });
  }