-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- continuing work on UserDataDirectory implementation, added V2 Conte…
…xt which supports more detailed configuration not requiring any special Startup files
- Loading branch information
andy.rozman
committed
Apr 6, 2024
1 parent
9241662
commit 270117d
Showing
4 changed files
with
313 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/com/atech/data/user_data_dir/v2/UserDataDirectoryContextV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.atech.data.user_data_dir.v2; | ||
|
||
import com.atech.data.FileDirectoryDto; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by andy on 27/01/18. | ||
*/ | ||
public interface UserDataDirectoryContextV2 { | ||
|
||
String getApplicationName(); | ||
|
||
String getApplicationDataDirectoryName(); | ||
|
||
String getFallbackDirectory(); | ||
|
||
List<FileDirectoryDto> getAllDirectoriesToCheck(); | ||
|
||
List<FileDirectoryDto> getAllFileToCheck(); | ||
} |
168 changes: 168 additions & 0 deletions
168
src/com/atech/data/user_data_dir/v2/UserDataDirectoryV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package com.atech.data.user_data_dir.v2; | ||
|
||
import com.atech.data.user_data_dir.UserDataDirectoryContext; | ||
import com.atech.update.startup.StartupUtil; | ||
import com.atech.update.startup.data.ApplicationStartupConfigDto; | ||
import com.atech.update.startup.data.StartupTypeDefinition; | ||
import com.atech.update.startup.os.OSType; | ||
import lombok.Getter; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Created by andy on 08/12/17. | ||
*/ | ||
|
||
public class UserDataDirectoryV2 | ||
{ | ||
|
||
//static String fallbackDirectory = "../data"; | ||
|
||
static String userDirectory; | ||
|
||
private static UserDataDirectoryV2 sUserDataDirectory; // = new UserDataDirectoryV2(); | ||
private final UserDataDirectoryContextV2 userDataDirectoryContextV2; | ||
//@Getter | ||
//ApplicationStartupConfigDto applicationStartupConfig; | ||
//String updateConfig; | ||
OSType osType; | ||
|
||
private StartupUtil startupUtil = new StartupUtil(); | ||
|
||
|
||
public static UserDataDirectoryV2 createInstance(UserDataDirectoryContextV2 applicationUDDContext) { | ||
sUserDataDirectory = new UserDataDirectoryV2(applicationUDDContext); | ||
return sUserDataDirectory; | ||
} | ||
|
||
|
||
public static UserDataDirectoryV2 getInstance() { | ||
return sUserDataDirectory; | ||
} | ||
|
||
|
||
private UserDataDirectoryV2(UserDataDirectoryContextV2 applicationUDDContext) { | ||
this.userDataDirectoryContextV2 = applicationUDDContext; | ||
initializeUserDataDirectory(); | ||
} | ||
|
||
|
||
public String getUserDataDirectory() { | ||
System.out.println("User Data Directory: " + userDirectory); | ||
return userDirectory; | ||
} | ||
|
||
|
||
private void initializeUserDataDirectory() | ||
{ | ||
// TODO add USB check, if this is USB installation data folder needs to be subfolder to current directory | ||
|
||
// if (this.applicationStartupConfig.isUsb()) | ||
// { | ||
// userDirectory = fallbackDirectory; | ||
// } | ||
// else | ||
{ | ||
this.osType = OSType.getOSByType(); | ||
|
||
if (this.osType == null) { | ||
this.osType = OSType.Unix; | ||
} | ||
|
||
String userDir = System.getProperty("user.home"); | ||
|
||
if (osType.getOSSpecificDataDirectory() != null) { | ||
userDir += "/" + osType.getOSSpecificDataDirectory(); | ||
} | ||
|
||
if (osType.isApplicationNamePrefixedWithDot()) { | ||
userDir += "/."; | ||
} else { | ||
userDir += "/"; | ||
} | ||
|
||
userDir += userDataDirectoryContextV2.getApplicationDataDirectoryName(); | ||
|
||
userDirectory = userDir; | ||
} | ||
} | ||
|
||
|
||
|
||
public String getParsedUserDataPath(String path) | ||
{ | ||
if (path.contains("%USER_DATA_DIR%")) | ||
{ | ||
path = path.replace("%USER_DATA_DIR%", userDirectory); | ||
} | ||
|
||
return path; | ||
} | ||
|
||
|
||
// public String getUpdateConfig() | ||
// { | ||
// if (updateConfig != null) | ||
// return updateConfig; | ||
// | ||
// if (applicationStartupConfig == null) | ||
// return null; | ||
// | ||
// String updateConfig = applicationStartupConfig.getUpdateConfigPath(); | ||
// | ||
// if (updateConfig == null) | ||
// return null; | ||
// | ||
// if (updateConfig.contains("%USER_DATA_DIR%")) | ||
// { | ||
// updateConfig = updateConfig.replace("%USER_DATA_DIR%", userDirectory); | ||
// } | ||
// | ||
// this.updateConfig = updateConfig; | ||
// | ||
// return updateConfig; | ||
// } | ||
|
||
public void migrateAndValidateData() { | ||
|
||
// TODO | ||
|
||
// 1.Check if target application directory exists | ||
// YES - Check that it contains all needed files | ||
// NO - go to 2. | ||
File userDirectoryFile = new File(userDirectory); | ||
|
||
|
||
if (userDirectoryFile.exists() && userDirectoryFile.isDirectory()) { | ||
|
||
} else { | ||
|
||
} | ||
|
||
|
||
// 2. Try to find data files of previous version (data defined in context, we can search | ||
// for specific directory in this directory or in some of the parents) | ||
// FOUND - go to 3. | ||
// NOT FOUND - go to 4. | ||
|
||
|
||
// 3. Migration scenario, copy all the files (directories to check) | ||
// from found directory. Do the check afterwards again. | ||
// IF ALL FILES THERE... EXIT | ||
// IF FILES NOT THERE need to copy them | ||
|
||
|
||
// 4. New Instalation scenario | ||
// create directory structure, unpack installation files | ||
|
||
|
||
|
||
|
||
// TODO | ||
//UserDataDirectoryMigration migration = new UserDataDirectoryMigration(this); | ||
//migration.process(); | ||
|
||
//x.GGCUserDataDirectoryExtractorValidator validator = new GGCUserDataDirectoryExtractorValidator("../ddda"); | ||
//userDataDirectoryExtractorValidator.validateAndRecreate(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/com/atech/data/user_data_dir/v2/UserDataDirectoryV2Validator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.atech.data.user_data_dir.v2; | ||
|
||
/** | ||
* Created by andy on 06.04.2024. | ||
*/ | ||
public class UserDataDirectoryV2Validator { | ||
|
||
|
||
public boolean isValidInstalation() { | ||
return false; | ||
} | ||
} |