Skip to content

Commit

Permalink
- continuing work on UserDataDirectory implementation, added V2 Conte…
Browse files Browse the repository at this point in the history
…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
Show file tree
Hide file tree
Showing 4 changed files with 313 additions and 9 deletions.
121 changes: 112 additions & 9 deletions src/com/atech/data/user_data_dir/UserDataDirectory.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,62 @@
package com.atech.data.user_data_dir;

import com.atech.data.user_data_dir.v2.UserDataDirectoryContextV2;
import com.atech.data.user_data_dir.v2.UserDataDirectoryV2Validator;
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 lombok.extern.slf4j.Slf4j;

import java.io.File;

/**
* Created by andy on 08/12/17.
*/
@Slf4j
public class UserDataDirectory
{

static String fallbackDirectory = "../data";

static String userDirectory;

private static UserDataDirectory sUserDataDirectory = new UserDataDirectory();
private static UserDataDirectory sUserDataDirectory; // = new UserDataDirectory(applicationUDDContext);
private UserDataDirectoryContextV2 userDataDirectoryContextV2;
@Getter
ApplicationStartupConfigDto applicationStartupConfig;
String updateConfig;
OSType osType;

private StartupUtil startupUtil = new StartupUtil();

public static UserDataDirectory getInstance()
{
public static UserDataDirectory createInstance(UserDataDirectoryContextV2 applicationUDDContext) {
sUserDataDirectory = new UserDataDirectory(applicationUDDContext);
return sUserDataDirectory;
}

public static UserDataDirectory createInstance() {
sUserDataDirectory = new UserDataDirectory();
return sUserDataDirectory;
}

private UserDataDirectory()
{
public static UserDataDirectory getInstance() {
return sUserDataDirectory;
}

private UserDataDirectory() {
initializeUserDataDirectory();
}

private UserDataDirectory(UserDataDirectoryContextV2 applicationUDDContext)
{
this.userDataDirectoryContextV2 = applicationUDDContext;
initializeUserDataDirectoryV2();
}




public String getUserDataDirectory()
{
Expand Down Expand Up @@ -94,9 +118,37 @@ private void initializeUserDataDirectory()
}


public ApplicationStartupConfigDto getApplicationStartupConfig()
{
return applicationStartupConfig;
private void initializeUserDataDirectoryV2() {
// 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;
}
}


Expand All @@ -113,6 +165,11 @@ public String getParsedUserDataPath(String path)

public String getUpdateConfig()
{
if (this.userDataDirectoryContextV2!=null) {
log.warn("UserDataDirectoryContextV2 doesn't use UpdateConfig V2/V3 anymore");
return null;
}

if (updateConfig != null)
return updateConfig;

Expand All @@ -134,13 +191,59 @@ public String getUpdateConfig()
return updateConfig;
}

public void migrateAndValidateData(/*UserDataDirectoryExtractorValidator*/ Object userDataDirectoryExtractorValidator) {
public void migrateAndValidateData(UserDataDirectoryContext userDataDirectoryContext) {
log.error("migrateAndValidateData not implemented for UserDataDirectory V1.");
}


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();


UserDataDirectoryV2Validator validator = new UserDataDirectoryV2Validator();

if (validator.isValidInstalation()) {

}
}

}
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 src/com/atech/data/user_data_dir/v2/UserDataDirectoryV2.java
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();
}
}
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;
}
}

0 comments on commit 270117d

Please sign in to comment.