/[svn]/jsampler/trunk/src/org/jsampler/HF.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/HF.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1142 by iliev, Mon Aug 7 18:25:58 2006 UTC revision 1143 by iliev, Mon Apr 2 21:18:31 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005 Grigor Kirilov Iliev   *   Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 27  import java.awt.Dialog; Line 27  import java.awt.Dialog;
27  import java.awt.Font;  import java.awt.Font;
28  import java.awt.Frame;  import java.awt.Frame;
29    
30    import java.io.File;
31    import java.io.FileInputStream;
32    import java.io.FileOutputStream;
33    
34  import java.util.logging.Level;  import java.util.logging.Level;
35    
36  import javax.swing.JOptionPane;  import javax.swing.JOptionPane;
# Line 214  public class HF { Line 218  public class HF {
218                  }                  }
219          }          }
220  ///////  ///////
221            
222            /**
223             * Deletes the specified file, if exists and
224             * is located in the JSampler's home directory.
225             * @param file The file to delete.
226             */
227            public static void
228            deleteFile(String file) {
229                    String s = CC.getJSamplerHome();
230                    if(s == null) return;
231                    
232                    try {
233                            File f = new File(s + File.separator + file);
234                            if(f.isFile()) f.delete();
235                    } catch(Exception x) {
236                            CC.getLogger().log(Level.INFO, getErrorMessage(x), x);
237                    }
238            }
239            
240            /**
241             * Create a backup copy of the specified file, located in the JSampler's home directory.
242             * @param file The name of the file to backup.
243             * @param bkpFile The backup name of the file.
244             * @return <code>true</code> if the file is backuped successfully.
245             */
246            public static boolean
247            createBackup(String file, String bkpFile) {
248                    if(file == null || bkpFile == null) return false;
249                    if(file.length() == 0 || bkpFile.length() == 0) return false;
250                    
251                    String s = CC.getJSamplerHome();
252                    if(s == null) return false;
253                    
254                    File f = new File(s + File.separator + file);
255                    if(!f.isFile()) return false;
256                    
257                    try {
258                            FileInputStream fis = new FileInputStream(s + File.separator + file);
259                            
260                            FileOutputStream fos;
261                            fos = new FileOutputStream(s + File.separator + bkpFile, false);
262                            
263                            int i = fis.read();
264                            while(i != -1) {
265                                    fos.write(i);
266                                    i = fis.read();
267                            }
268                    } catch(Exception x) {
269                            CC.getLogger().log(Level.INFO, getErrorMessage(x), x);
270                            return false;
271                    }
272                    
273                    return true;
274            }
275            
276            
277  }  }

Legend:
Removed from v.1142  
changed lines
  Added in v.1143

  ViewVC Help
Powered by ViewVC