#navi(contents-page-name): No such page: ST

FrontPage

Terai Atsuhiro 2021-12-14 (火) 18:52:02

xyzzy

private File makeBackupFile(File file, int intold, int intnew){
  File testFile = null;
  String newfilename = file.getAbsolutePath();
  if(intold==0 && intnew==0){
    file.delete();
    return new File(newfilename);
  }
  boolean testFileFlag = false;
  for(int i=1;i<=intold;i++){
    testFile = new File(file.getParentFile(), file.getName()+"."+i+"~");
    if(!testFile.exists()){
      testFileFlag = true;
      break;
    }
  }
  if(!testFileFlag){
    for(int i=intold+1;i<=intold+intnew;i++){
      testFile = new File(file.getParentFile(), file.getName()+"."+i+"~");
      if(!testFile.exists()){
        testFileFlag = true;
        break;
      }
    }
  }
  if(testFileFlag){
    Logger.global.info("createBKUP1"+testFile.getAbsolutePath());
    file.renameTo(testFile);
  }else{
    File tmpFile3 = new File(file.getParentFile(),
                             file.getName()+"."+(intold+1)+"~");
    tmpFile3.delete();
    for(int i=intold+2;i<=intold+intnew;i++){
      File tmpFile1 = new File(file.getParentFile(),
                               file.getName()+"."+i+"~");
      File tmpFile2 = new File(file.getParentFile(),
                               file.getName()+"."+(i-1)+"~");
      tmpFile1.renameTo(tmpFile2);
    }
    File tmpFile = new File(file.getParentFile(),
                            file.getName()+"."+(intold+intnew)+"~");
    Logger.global.info("changeBKUP2"+tmpFile.getAbsolutePath());
    file.renameTo(tmpFile);
  }
  //Logger.global.info(newfilename);
  return new File(newfilename);
}

xyzzy

File tmpFile = File.createTempFile("fontemp", "fo~", file.getParentFile());
//UXMLDocument.saveElement(elm, tmpFile, "Shift_JIS", true, 2);
//int iold = 0;
//int inew = 0;
//if(prefs.getBoolean("flag_bkup", true)){
//  iold = prefs.getInt("bkup_old", 2);
//  inew = prefs.getInt("bkup_new", 3);
//}
file = makeBackupFile(file, 2, 3);
tmpFile.renameTo(file);